Created
March 7, 2015 14:08
-
-
Save kiarina/7abf6c67ab27aea13bad to your computer and use it in GitHub Desktop.
Script for Illustrator. A png picture is output every layer.
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 options = new ExportOptionsPNG24(); | |
var folder = Folder.selectDialog(); | |
var doc = app.activeDocument; | |
if (doc && folder) { | |
var newdoc = app.documents.add(doc.documentColorSpace, doc.width, doc.height); | |
newdoc.artboards[0].artboardRect = doc.artboards[0].artboardRect; | |
saveSubLayers(doc, folder); | |
newdoc.close(SaveOptions.DONOTSAVECHANGES); | |
} | |
function saveSubLayers (node, path) { | |
for (var i = 0; i < node.layers.length; i++) { | |
var layer = node.layers[i]; | |
if (!layer.visible) continue; | |
if (layer.layers.length > 0) | |
saveSubLayers(layer, path + "/" + layer.name); | |
else | |
saveLayer(layer, path); | |
} | |
} | |
function saveLayer (layer, path) { | |
newdoc.layers[0].remove(); | |
var newlayer = newdoc.layers[0]; | |
for (var ii = layer.pageItems.length - 1; ii >= 0; ii--) | |
layer.pageItems[ii].duplicate(newlayer, ElementPlacement.PLACEATBEGINNING); | |
new Folder(path).create(); | |
newdoc.exportFile(new File(path + "/" + layer.name + ".png"), ExportType.PNG24, options); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment