From d4c5cbfb205612062dd756847e1831c1f566033a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=20Mun=CC=83oz?= Date: Thu, 16 Jul 2015 09:21:17 +0200 Subject: [PATCH] Added Export Symbols command --- Export Symbols.sketchplugin | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Export Symbols.sketchplugin diff --git a/Export Symbols.sketchplugin b/Export Symbols.sketchplugin new file mode 100644 index 0000000..b0fa4c1 --- /dev/null +++ b/Export Symbols.sketchplugin @@ -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] + } +}