-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathExport Symbols.sketchplugin
31 lines (27 loc) · 1.06 KB
/
Export Symbols.sketchplugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var layers = [[doc currentPage] layers],
document_path = [[doc fileURL] path].split([doc displayName])[0],
currentFilePath = [[doc fileURL] path];
// Loop through layers, picking symbols:
var allSymbols = {}
for (var i=0; i < [layers count]; i++) {
var current = [layers objectAtIndex:i],
currentID = current.sharedObjectID()
if (currentID != null ) {
// 'current' is a symbol instance
// make sure we're not storing duplicated instances:
allSymbols[currentID] = current
}
}
if(Object.keys(allSymbols).length == 0){
[doc showMessage:"Please place a symbol on the canvas"]
} else {
for (var currentID in allSymbols) {
var currentSymbol = allSymbols[currentID],
symbolName = [currentSymbol name],
exportFilename = document_path + "/" + symbolName + ".png",
slice = [[MSExportRequest exportRequestsFromExportableLayer:currentSymbol] firstObject]
slice.page = [[doc currentPage] copyLightweight]
slice.format = "png"
[[MSSliceExporter dataForRequest:slice] writeToFile:exportFilename atomically:true]
}
}