Skip to content

Instantly share code, notes, and snippets.

@seanriceaz
Last active October 3, 2016 18:08
Show Gist options
  • Save seanriceaz/7c94e64fe1ab9f02a9d3335d5228a5d7 to your computer and use it in GitHub Desktop.
Save seanriceaz/7c94e64fe1ab9f02a9d3335d5228a5d7 to your computer and use it in GitHub Desktop.
This script will loop through layers in the first two layer groups in a photoshop file toggling them one by one and exporting a png of each flattened combination
// This script will loop through layers in the first two layer groups
// in a photoshop file toggling them one by one and exporting a png of
// each flattened combination
// NOTE: Start the file with all the grouped layers set invisible,
// but the groups themselves visible, and any non-grouped layets you want
// to put in all the files visible.
#target photoshop
var MyGroups = app.activeDocument.layerSets;
var filePath="~/Desktop/"; //Change this to where you want to output the files to go
//Loop through group 1
var i;
for(i = 0; i < MyGroups[0].layers.length; i++) {
//Set which group 1 layer we're working with
var obj = MyGroups[0].layers[i];
//turn this layer on
obj.visible=true;
//Loop through group 2
var j;
for(j = 0; j < MyGroups[1].layers.length; j++) {
//set which layer in group 2 we're working with
var objinner = MyGroups[1].layers[j];
//turn this layer on
objinner.visible = true;
//Save file
var fileName = obj.name + "-" + objinner.name;
var fileNamePath = filePath + fileName+".png";
SavePNG(fileNamePath);
//turn this layer off
objinner.visible = false;
//Next!
}
//turn off our group 1 layer
obj.visible=false;
}
function SavePNG(saveFile){
var pngOpts = new ExportOptionsSaveForWeb;
pngOpts.format = SaveDocumentType.PNG;
pngOpts.PNG8 = false;
pngOpts.transparency = true;
pngOpts.interlaced = false;
pngOpts.quality = 100;
activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment