Skip to content

Instantly share code, notes, and snippets.

@ashleahhill
Created September 6, 2013 00:53
Show Gist options
  • Select an option

  • Save ashleahhill/6458198 to your computer and use it in GitHub Desktop.

Select an option

Save ashleahhill/6458198 to your computer and use it in GitHub Desktop.
Export Layer to Folder Adobe Extend Script
var docRef, docLayers, myFolder, myOutput, pngExportOptions;
docRef = app.activeDocument;
docLayers = docRef.artLayers;
myOutput = {
name: docRef.name.replace(/\.pdf/,''),
path: docRef.path,
fullPath: docRef.path + '/' + docRef.name.replace(/\.pdf/,'')
}
myFolder = new Folder (myOutput.fullPath);
pngExportOptions = {
format: SaveDocumentType.PNG-24
};
// new File creates file if it doesn't exist, new Folder does not.
if (!myFolder.exists) {
myFolder.create()
}
// to do: make recursive, want document Art Layers and Art Layers inside Layer Sets
exportLayers(docLayers);
function exportLayers(theLayers){
for(i=0; i<theLayers.length; i++){
var thisLayer, newDoc, myFile;
thisLayer = theLayers[i];
if (thisLayer.visible) {
newDoc = app.documents.add(1000, 1000, 72, thisLayer.name, NewDocumentMode.RGB, DocumentFill.TRANSPARENT);
app.activeDocument = docRef;
thisLayer.duplicate(newDoc, ElementPlacement.PLACEATEND);
app.activeDocument = newDoc;
myFile = new File (myOutput.fullPath + '/' + thisLayer.name + '.png');
newDoc.exportDocument(myFile, ExportType.SAVEFORWEB, pngExportOptions);
newDoc.close(SaveOptions.DONOTSAVECHANGES);
app.activeDocument = docRef;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment