Skip to content

Instantly share code, notes, and snippets.

@calvinchengx
Created April 25, 2011 07:57
Show Gist options
  • Save calvinchengx/940263 to your computer and use it in GitHub Desktop.
Save calvinchengx/940263 to your computer and use it in GitHub Desktop.
Export each layer as a PNG from your Illustrator file.
var document = app.activeDocument;
if(document && folder)
{
var options = new ExportOptionsPNG24();
options.antiAliasing = true;
options.transparency = true;
var n = document.layers.length;
for(var i=0; i<n; ++i)
{
hideAllLayers();
var layer = document.layers[i];
layer.visible = true;
var file = new File(folder.fsName+"/"+layer.name+".png");
var options = new ExportOptionsPNG24();
options.artBoardClipping = true;
document.exportFile(file,ExportType.PNG24,options);
}
showAllLayers();
}
function hideAllLayers()
{
forEach(document.layers, function(layer) {
layer.visible = false;
});
}
function showAllLayers()
{
forEach(document.layers, function(layer) {
layer.visible = true;
});
}
function forEach(collection, fn)
{
var n = collection.length;
for(var i=0; i<n; ++i)
{
fn(collection[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment