Created
August 6, 2014 18:18
-
-
Save bomberstudios/6397517fb84d2f0b124c to your computer and use it in GitHub Desktop.
Export Symbols from Canvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment