Created
February 5, 2014 17:59
-
-
Save nicloay/8829596 to your computer and use it in GitHub Desktop.
Export adobe illustrator visible layers to png files with the same layer name structure (layers->sublayers becomes folder->subfolders)
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
// Export Layers as PNG files with original layer structure | |
var options = new ExportOptionsPNG24(); | |
var doc = app.activeDocument; | |
$.writeln("trying to save"); | |
var newdoc = app.documents.add(doc.documentColorSpace, doc.width, doc.height); | |
newdoc.artboards[0].artboardRect = doc.artboards[0].artboardRect; | |
saveSubLayers(doc, ""); | |
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(doc.path + path).create(); | |
newdoc.exportFile(new File(doc.path + 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
How would this be edited to retain artboard sizes vs. snapping to the layers artwork dimensions?