Skip to content

Commit

Permalink
Added Export Symbols command
Browse files Browse the repository at this point in the history
  • Loading branch information
bomberstudios committed Jul 16, 2015
1 parent 47e54ee commit d4c5cbf
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Export Symbols.sketchplugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 = [[MSSliceMaker slicesFromExportableLayer:currentSymbol] firstObject]

slice.page = [[doc currentPage] copyLightweight]
slice.format = "png"
[[MSSliceExporter dataForRequest:slice] writeToFile:exportFilename atomically:true]
}
}

0 comments on commit d4c5cbf

Please sign in to comment.