This content has been marked as final.
Show 10 replies
-
1. Re: Javascript template for cs4 needed
c.pfaffenbichler Mar 12, 2009 2:44 AM (in response to Paulo Skylar)That doesnt sound too bad.
But how do You mark subject variation-layers as opposed to scene-layers?
Do they adhere to a naming-convention or are they stacked in a defined order (possibly in layer sets)?
Because obviously the Script would have to be able to identify the members of the two groups. -
2. Re: Javascript template for cs4 needed
Paulo Skylar Mar 12, 2009 8:33 AM (in response to Paulo Skylar)The answer is naming conventions. All of the subject psd files have the same naming structure. So for each file to be written the visibility of, say for example , Scene 0 and subject 4 would have to be turned on and then saved as a jpeg, somehow using the codes 0 and 4 in the file id.
Paulo -
3. Re: Javascript template for cs4 needed
c.pfaffenbichler Mar 12, 2009 10:57 PM (in response to Paulo Skylar)Provided none of the layers reside in a Layer Set, which would make things a bit more complicated, You could give this a try (»scene« and »subject« both in lower case though, You can change that easily in the Script):
#target photoshop
var myDocument = app.activeDocument;
var docName = myDocument.name;
var baseName = docName.match(/(.*)\.[^\.]+$/)[1];
var docPath = myDocument.path;
var jpgOptions = new JPEGSaveOptions();
jpgOptions.embedProfile = true;
jpgOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgOptions.matte = MatteType.NONE;
jpgOptions.quality = 10;
theFolder = Folder.selectDialog("select a folder to save the jpgs to");
var theStart = myDocument.activeHistoryState;
var theScenes = new Array;
var theSubjects = new Array;
for (var m = 0; m < myDocument.layers.length; m++ ) {
var theLayerName = myDocument.layers[m].name;
switch (theLayerName.slice(0, 5)) {
case "scene": theScenes = theScenes.concat (theLayerName);
break;
case "subje": theSubjects = theSubjects.concat (theLayerName);
break}
};
for (var n = 0; n < myDocument.layers.length; n++ ) {
myDocument.layers[n].visible = false;
};
for (var o = 0; o < theScenes.length; o++ ) {
myDocument.layers[ theScenes[o] ].visible = true;
for (var p = 0; p < theSubjects.length; p++ ) {
myDocument.layers[ theSubjects[p] ].visible = true;
var theCopy = myDocument.duplicate (theCopy, true);
theCopy.bitsPerChannel = BitsPerChannelType.EIGHT;
theCopy.saveAs((new File(theFolder+"/"+baseName+"_"+theScenes[o].slice(-1)+"_"+theSubjects[p].slice(-1)+".jpg")),jpgOptions,true);
theCopy.close(SaveOptions.DONOTSAVECHANGES);
myDocument.layers[ theSubjects[p] ].visible = false
};
myDocument.layers[ theScenes[o] ].visible = false;
};
myDocument.activeHistoryState = theStart;
// thats it; thanks to xbytor;
// use it at your own risk; -
4. Re: Javascript template for cs4 needed
Paulo Skylar Mar 13, 2009 7:48 AM (in response to Paulo Skylar)christoph
Many thanks for this proposed solution. Even if some details need to be changed, having a great starting point like this is a most welcomed contribution. I am currently out of town and away from my office, but when I return at the beginning of the week I will see how this code performs.
I am in your debt. While it did not start out this way, the current state of the project requires the creation of 1080 images and that is far too many without some automation.
Thanks again,
Paulo -
5. Re: Javascript template for cs4 needed
c.pfaffenbichler Mar 15, 2009 5:35 AM (in response to Paulo Skylar)Youre welcome.
But I must admit I cut two corners:
Firstly I didnt sufficiently comment the posted Script, which I could remedy if You consider it necessary.
Secondly I supposed the numbers for Scenes and Subjects would be between zero and nine, so that slicing the last letter of the name should provide discernable identification for the newly saved files. With higher numbers some files would simply get replaced without notice. So it would be prudent to implement some method to grab the whole of the numbers. -
6. Re: Javascript template for cs4 needed
Paulo Skylar Mar 15, 2009 7:56 AM (in response to Paulo Skylar)I think the sparse commenting will not be a problem especially since I will use this code as an opportunity to learn more about Javascript. I also understand your warning about the naming of the files.
I have learned a relevant thing about nomenclature. That is, your warning about "layer sets" is relevant since I do have some "layer groups" in my psd files. Apparently, those designations are the old and new names for the same thing in Photoshop and I will have to deal with those complications. Would using scriptlistener be helpful in learning how to change the visibility of a layer set?
Paulo -
7. Re: Javascript template for cs4 needed
c.pfaffenbichler Mar 15, 2009 8:32 AM (in response to Paulo Skylar)Regarding the nomenclature You can check out the Object Model Viewer in ExtendScript Toolkit or »Photoshop CS4 JavaScript Ref.pdf«.
The visibility of a LayeSet can be changed just like a Layers:
"app.activeDocument.layers["the groups name"].visibility = true"
And the matter can get difficult because a Layer is the child of a Document only if it does not reside in a LayerSet, in which case it is that LayerSets child, meaning one has to address it not as "app.activeDocument.layers["the layers name or index"]" but "app.activeDocument.layers["the groups name or index"].layers["the layers name or index"]" and so on, as far as I know.
How are the LayerSets and the ArtLayers organized with regard to the visibility demands for the jpgs? -
8. Re: Javascript template for cs4 needed
Paulo Skylar Mar 20, 2009 8:26 AM (in response to Paulo Skylar)Christopf,
Sorry for the late reply, just returned to the office.
In any psd file that contains one or more layer sets, the layer sets are all unique, that is, there is no common organization in them as I used whatever function or effects necessary to get the desired overall result. I am not sure if this answers your question or not, but wherever a layer set exists all layers in the set have visibility turned on and it would be the set (or group) whose visibility would be changed. Specifically, any set that exists is a scene and the set name is the scene name.
Paulo -
9. Re: Javascript template for cs4 needed
c.pfaffenbichler Mar 21, 2009 1:08 AM (in response to Paulo Skylar)In that case treating the groups as layers should work out as long as their names follow the same conventions.
The visibility of the layers inside the groups should not get changed by turning the groups visibility on and off.
I guess. -
10. Re: Javascript template for cs4 needed
Paulo Skylar Mar 21, 2009 7:38 AM (in response to Paulo Skylar)Great, I think the solution for my problem is coming into focus.
Thanks again,
Paulo


