Often many of my psd's have multiple 'options' in a sense. For example, there may be a box that has 3 different color adjustment layers: blue, black, and red. On top of that, I may have 20 different items, such as a coffee mug, a ball, etc. Everything is its own layer, and I need to export each combination of color and item to its own psd or jpeg. I have been using an action to select on and off the item images, creating layer comps, and then exporting them to files with each color selected. I was wondering if there was an easy way to merge all of these steps into a script. Grouping each separate 'variable', and having the script create layer comps for every combination and export them all.
Along with this, I've been trying to edit the layer comps to files script to help with the naming of files. I have searched but I cannot seem to find how to name the files based on the layers instead of the layer comps. Such as <var1> <var2>, or "blue coffee mug", given the layer 'blue' and 'coffee mug'.
EDIT: It seems as though the newest version of "Picture Processor" has renaming; I'll look into that for the second issue.
Script for Processing Large Combinations of Layers
Script for Processing Large Combinations of Layers
Could you post a lores sample of a layered version and the resulting files to clarify the layer structure, naming conventions …?
Script for Processing Large Combinations of Layers
I'm having trouble uploading the file, but here is a more detailed description of what I would need.
The psd would contain one group of layers containing various color adjustments; the layers would be named 'light-blue' 'red' 'yellow', etc. The next group of layers would consist of different shapes; named 'square', 'ellipse', etc. From there, the file names for each of the output files would be 'light blue square.jpg', 'red square.jpg', 'yellow square.jpg', 'light blue ellipse.jpg', 'red ellipse.jpg', 'yellow ellipse.jpg', etc. These would be solely based off of the names of the layers. Eventually this would evolve into each 'shape' being a SKU number, and each 'color' becoming an option number.
The psd would contain one group of layers containing various color adjustments; the layers would be named 'light-blue' 'red' 'yellow', etc. The next group of layers would consist of different shapes; named 'square', 'ellipse', etc. From there, the file names for each of the output files would be 'light blue square.jpg', 'red square.jpg', 'yellow square.jpg', 'light blue ellipse.jpg', 'red ellipse.jpg', 'yellow ellipse.jpg', etc. These would be solely based off of the names of the layers. Eventually this would evolve into each 'shape' being a SKU number, and each 'color' becoming an option number.
Script for Processing Large Combinations of Layers
So there are two layerSets in the file and nothing else?
And those two can be identified by their positions, the group with the adjustment layers being the top one, I expect?
And those two can be identified by their positions, the group with the adjustment layers being the top one, I expect?
Script for Processing Large Combinations of Layers
For a simple case (two groups with the adjustment layers and layers respectively) you could try something like this:
Code: Select all// 2011; use it at your own risk;
#target photoshop
// check and get back array of selected layer;
checksOut = checkPhotoshop();
if (checksOut == true) {
app.togglePalettes();
// define document;
var myDocument = app.activeDocument;
// thanks to xbytor for regexp;
var docName = myDocument.name;
var basename = docName.match(/(.*)\.[^\.]+$/)[1];
var docPath = myDocument.path;
var set1 = myDocument.layers[0];
set1.visible = true;
var set2 = myDocument.layers[1];
set2.visible = true;
// psd options;
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = false;
psdOpts.layers = true;
psdOpts.spotColors = true;
// hide layers;
for (var a = 0; a < set2.layers.length; a++) {
set2.layers[a].visible = false
};
for (var b = 0; b < set1.layers.length; b++) {
set1.layers.visible = false
};
// process layers;
for (var c = 0; c < set2.layers.length; c++) {
var layer2 = set2.layers[c];
layer2.visible = true;
for (var d = 0; d < set1.layers.length; d++) {
// show one adjustment;
var layer1 = set1.layers[d];
layer1.visible = true;
// duplicate the image;
var thecopy = myDocument.duplicate (myDocument, true);
thecopy.saveAs((new File(docPath+'/'+basename+"_"+layer1.name+"_"+layer2.name+".psd")),psdOpts,true);
thecopy.close(SaveOptions.DONOTSAVECHANGES);
// hide adjustment;
layer1.visible = false;
};
// hide layer;
layer2.visible = false;
};
app.togglePalettes();
};
////// check if file is eligible for this script //////
function checkPhotoshop() {
var checksOut = true;
if (app.documents.length == 0) {
alert("no documents are open\nplease open a document and try again");
checksOut = false
}
else {
if (app.activeDocument.layers.length != 2) {
alert("the current document does not fit");
checksOut = false
}
else {
if (app.activeDocument.layers[0].typename != "LayerSet" || app.activeDocument.layers[1].typename != "LayerSet") {
alert("the current document does not have two layersets");
checksOut = false
}
}
};
return checksOut
};
Code: Select all// 2011; use it at your own risk;
#target photoshop
// check and get back array of selected layer;
checksOut = checkPhotoshop();
if (checksOut == true) {
app.togglePalettes();
// define document;
var myDocument = app.activeDocument;
// thanks to xbytor for regexp;
var docName = myDocument.name;
var basename = docName.match(/(.*)\.[^\.]+$/)[1];
var docPath = myDocument.path;
var set1 = myDocument.layers[0];
set1.visible = true;
var set2 = myDocument.layers[1];
set2.visible = true;
// psd options;
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = false;
psdOpts.layers = true;
psdOpts.spotColors = true;
// hide layers;
for (var a = 0; a < set2.layers.length; a++) {
set2.layers[a].visible = false
};
for (var b = 0; b < set1.layers.length; b++) {
set1.layers.visible = false
};
// process layers;
for (var c = 0; c < set2.layers.length; c++) {
var layer2 = set2.layers[c];
layer2.visible = true;
for (var d = 0; d < set1.layers.length; d++) {
// show one adjustment;
var layer1 = set1.layers[d];
layer1.visible = true;
// duplicate the image;
var thecopy = myDocument.duplicate (myDocument, true);
thecopy.saveAs((new File(docPath+'/'+basename+"_"+layer1.name+"_"+layer2.name+".psd")),psdOpts,true);
thecopy.close(SaveOptions.DONOTSAVECHANGES);
// hide adjustment;
layer1.visible = false;
};
// hide layer;
layer2.visible = false;
};
app.togglePalettes();
};
////// check if file is eligible for this script //////
function checkPhotoshop() {
var checksOut = true;
if (app.documents.length == 0) {
alert("no documents are open\nplease open a document and try again");
checksOut = false
}
else {
if (app.activeDocument.layers.length != 2) {
alert("the current document does not fit");
checksOut = false
}
else {
if (app.activeDocument.layers[0].typename != "LayerSet" || app.activeDocument.layers[1].typename != "LayerSet") {
alert("the current document does not have two layersets");
checksOut = false
}
}
};
return checksOut
};
Script for Processing Large Combinations of Layers
That seems to work great! It seems to be a good starting point thanks a lot. I was not expecting an entire script to be written, you didn't have to do that.
From there, the only thing that would help greatly is if it worked with groups within groups, such that the color adjustments could consist of color balance and curve adjustment layers, and if it worked if there was a base background image. Please don't spend too much time on this, a point in the right direction of how to approach this would be fine; I kind of enjoy trying to figure it out!
From there, the only thing that would help greatly is if it worked with groups within groups, such that the color adjustments could consist of color balance and curve adjustment layers, and if it worked if there was a base background image. Please don't spend too much time on this, a point in the right direction of how to approach this would be fine; I kind of enjoy trying to figure it out!
Script for Processing Large Combinations of Layers
For a background layer to be included you would have to get rid of the
Code: Select all if (app.activeDocument.layers.length != 2) {
conditional clause.
But the Script would then run on the assumption that the first two layers are the layerSets to combine.
he only thing that would help greatly is if it worked with groups within groups, such that the color adjustments could consist of color balance and curve adjustment layers,
How exactly would they have to be combined or would every adjustment have to be applied for itself?
If the group should be applied in its entirety that should work as is, because the group should be addressed by »set2.layers[c]« anyway.
I kind of enjoy trying to figure it out!
I can understand that.
Code: Select all if (app.activeDocument.layers.length != 2) {
conditional clause.
But the Script would then run on the assumption that the first two layers are the layerSets to combine.
he only thing that would help greatly is if it worked with groups within groups, such that the color adjustments could consist of color balance and curve adjustment layers,
How exactly would they have to be combined or would every adjustment have to be applied for itself?
If the group should be applied in its entirety that should work as is, because the group should be addressed by »set2.layers[c]« anyway.
I kind of enjoy trying to figure it out!
I can understand that.
Script for Processing Large Combinations of Layers
Ah, I definitely missed both of those; now that you pointed it out it makes complete sense. I wasn't sure if calling .layers[x] also worked with groups, but I will have a chance to test it later. Thanks again for the help.