Skip to content

Commit 3305b33

Browse files
committed
Add a new command - create symbol instance
1 parent 809e2ed commit 3305b33

File tree

5 files changed

+78
-3
lines changed

5 files changed

+78
-3
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# CODING Toolkit Sketch Plugin
22

3-
<img src='https://user-images.githubusercontent.com/5106039/80296781-61060600-87b0-11ea-8dd4-d9a15d29d9cd.png' width='674px'>
3+
<img src='https://user-images.githubusercontent.com/5106039/80345374-9c313380-889b-11ea-9686-2e3d2d6ee4ac.png' width='839px'>
44

55
## 插件命令
6+
Dev Library 分类中的命令主要用于开发 Sketch Library 时使用。
67

78
### 1. Update Icon 升级图标
89
用于替换旧版 CODING Icon 至新版 CODING Icon,在设计稿中选中来自旧版的 CODING Icon Library 的 symbol 然后执行此命令即可自动替换为对应的新版 CODING ICON,并且保留原来 icon 覆盖的颜色。
@@ -11,6 +12,9 @@
1112
用与在 CODING Icon Library 文件中修改或添加 icon 后重新生成 icon 集合,以便在 Abstract 中查找 icon。执行此命令将会自动删除原 Page 1 中的 icon collection 画板然后重新生成新的画板。
1213
更新 CODING Icon 的具体方法请查看此 [Wiki](https://codingcorp.coding.net/p/Design-Center/wiki/1495)
1314

15+
### 3. Create Symbol Instance 通过选中的 Symbol Master 创建 Instance
16+
选中一个或多个 Symbol Master 后执行此命令,可自动在 Symbol Master 下方创建对应的 instance,用于快速预览和检查 Symbol Master 的使用效果与 Overrides 配置。
17+
1418
## Installation
1519

1620
- [Download](../../releases/latest/download/coding-toolkit.sketchplugin.zip) the latest release of the plugin

src/create-symbol-instance.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sketch from 'sketch'
2+
3+
export default function() {
4+
const document = sketch.getSelectedDocument()
5+
const selection = document.selectedLayers.layers
6+
const SymbolInstance = sketch.SymbolInstance
7+
8+
const currentPage = document.selectedPage
9+
const notSymbolArrary = []
10+
11+
// Create symbol instance under selected symbol
12+
selection.map(symbolMaster => {
13+
if (symbolMaster.symbolId) {
14+
let instance = new SymbolInstance({
15+
name: symbolMaster.name,
16+
parent: currentPage,
17+
frame: symbolMaster.frame,
18+
symbolId: symbolMaster.symbolId,
19+
})
20+
instance.frame.y = instance.frame.y + instance.frame.height
21+
} else {
22+
notSymbolArrary.push(symbolMaster.name)
23+
}
24+
})
25+
26+
// Show the layers which not symbol
27+
if (notSymbolArrary.length > 0 ) {
28+
sketch.UI.message(`‼️ Error: Layer '${notSymbolArrary.join(', ')}' not a symbol !`)
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sketch from 'sketch'
2+
3+
export default function() {
4+
const document = sketch.getSelectedDocument()
5+
const selection = document.selectedLayers.layers
6+
const SymbolInstance = sketch.SymbolInstance
7+
8+
const currentPage = document.selectedPage
9+
const notSymbolArrary = []
10+
11+
// Create symbol instance under selected symbol
12+
selection.map(symbolMaster => {
13+
if (symbolMaster.symbolId) {
14+
let instance = new SymbolInstance({
15+
name: symbolMaster.name,
16+
parent: currentPage,
17+
frame: symbolMaster.frame,
18+
symbolId: symbolMaster.symbolId,
19+
})
20+
instance.frame.y = instance.frame.y + instance.frame.height
21+
} else {
22+
notSymbolArrary.push(symbolMaster.name)
23+
}
24+
})
25+
26+
// Show the layers which not symbol
27+
if (notSymbolArrary.length > 0 ) {
28+
sketch.UI.message(`‼️ Error: '${notSymbolArrary.join(', ')}' is not a symbol !`)
29+
}
30+
}

src/manifest.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,25 @@
1010
{
1111
"name": "Generate Icon Library Collection",
1212
"identifier": "coding-toolkit.generate-icons-collection",
13-
"script": "./generate-icons-collection.js"
13+
"script": "./dev-library/generate-icons-collection.js"
14+
},
15+
{
16+
"name": "Create Symbol Instance",
17+
"identifier": "coding-toolkit.create-symbol-instance",
18+
"script": "./dev-library/create-symbol-instance.js"
1419
}
1520
],
1621
"menu": {
1722
"title": "🐤 CODING Toolkit",
1823
"items": [
1924
"coding-toolkit.update-icon",
20-
"coding-toolkit.generate-icons-collection"
25+
{
26+
"title": "Dev Library",
27+
"items": [
28+
"coding-toolkit.generate-icons-collection",
29+
"coding-toolkit.create-symbol-instance"
30+
]
31+
}
2132
]
2233
}
2334
}

0 commit comments

Comments
 (0)