Skip to content

Instantly share code, notes, and snippets.

@kiarina
Created March 7, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiarina/7abf6c67ab27aea13bad to your computer and use it in GitHub Desktop.
Save kiarina/7abf6c67ab27aea13bad to your computer and use it in GitHub Desktop.
Script for Illustrator. A png picture is output every layer.
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