例图:
1.获取初始化信息
在看了Developer开发指南之后, 应该会写出第一个插件,可以保存就可以运行 .
module.exports = {
// 初始化sketch的基础值
initContext: function (context) {
this.plugin = context.plugin,
this.command = context.command,
this.document = context.document,
this.page = this.doc.currentPage(),
this.artboards = this.page.artboards(),
this.selectedArtboard = this.page.currentArtboard(), // 当前被选择的画板
this.selection = context.selection,
}
log('plugin:' + this.plugin + 'command:' + this.command + ' document:' + this.document + ' page:' + this.page + ' artboard:' + this.artboards + " selectedArt:" + this.selectedArtboard + " selection:" + this.selection);
};
打印输出结果:
plugin:<MSPluginBundle: 0x6040008e7b80>
command:<MSPluginCommand: 0x6000010f8100>
document:<MSDocument: 0x7fb7f2cadb80>
page:<MSPage: 0x7fb7f7b69b00> Page 1 (584BCD5E-FD61-491F-A566-F30DAF56C9C8)
artboard:(\n "<MSArtboardGroup: 0x7fb7f2c65390> iPhone 8 (B1162BAA-B284-449B-B3DE-E8477E15D72D)"\n)
selectedArtboard:<MSArtboardGroup: 0x7fb7f2c65390> iPhone 8 (B1162BAA-B284-449B-B3DE-E8477E15D72D)
selection:(\n "<MSLayerGroup: 0x7fb7f2e219b0> BigPictureAdView (BA7737EA-F265-43D7-B300-F728D20FA890)"\n)'
command: MSPluginCommand
对象,代表当前执行的命令
document: MSDocument
对象 ,当前的文档*
plugin: MSPluginBundle
对象,当前的插件bundle,里面包含当前运行的脚本
selection,一个 NSArray
对象,包含了当前选择的所有图层。数组中的每一个元素都是 MSLayer
对象
selectedArtboard:MSArtboardGroup
对象,当前画板信息
selection:MSLayerGroup
对象 , 选中的组
2.去对应的sketch-header中寻找对应类
拿MSPluginBundle
举例
可以看到, MSPluginBundle类中有许多的属性可以获取,根据cocoscript的语法规则
如果要获取
var name = this.plugin.name();
上一篇 : sketch开发之Json2View(一) 准备工作
下一篇:sketch开发之Json2View(三) 获取选中控件