🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.photoshop.scripting
11 messages
11 total messages Started by Paulo_Skylar Sat, 07 Mar 2009 16:54
Javascript template for cs4 needed
#181
Author: Paulo_Skylar
Date: Sat, 07 Mar 2009 16:54
21 lines
2194 bytes
I am in need of some help to create a javascript to write jpeg files from PS-CS4 psd files. What would be most useful is a pointer to a suitable Javascript template to tailor to my needs. The operations seem simple enough, but my only scripting experience is limited to simple ActionScript 3.0 .

I have numerous psd files each of which has 12 layers (some layers are groups). Think of these as 3 scene layers and 9 subject variation layers. I need to select a scene layer, select a subject variation layer and then write a jpeg file of that composition to a folder. The file name wants to be psdname_scenelayername_subjectvariationname.jpg, where each of the names is taken from the open psd file and the layers selected. This is then repeated so that each subject layer (9) is paired with each scene layer (9) yielding 27 separate files. I actually have to do this with various psd files, but I can manually run the script on each psd file for now instead of batch processing. This sounds like setting layer comps and then sending comps to files, but the subject variation layers contain smart objects and adjustment layers that layer comps (apparently) cannot track.

So it seems that on an open psd file I need to:

set the visibility of all layers off
set the visibility of scene A on
set the visibility of subject variation 1 on
save as jpeg
    set name (psdname_A_1.jpg)
    set jpeg quality
    set destination folder
repeat above for each subject variation, changing the jpg file name
repeat above for each scene, changing the jpg file name
end

Any help in getting this automation started would be appreciated.

Thanks,
Paulo
Re: Javascript template for cs4 needed
#118
Author: christoph_pfaffenbichler
Date: Thu, 12 Mar 2009 10:44
4 lines
894 bytes
That doesn�t 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.
Re: Javascript template for cs4 needed
#123
Author: Paulo_Skylar
Date: Thu, 12 Mar 2009 16:33
3 lines
965 bytes
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
Re: Javascript template for cs4 needed
#124
Author: christoph_pfaffenbichler
Date: Fri, 13 Mar 2009 06:57
83 lines
2573 bytes
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; 

// that�s it; thanks to xbytor; 

// use it at your own risk;
Re: Javascript template for cs4 needed
#131
Author: Paulo_Skylar
Date: Fri, 13 Mar 2009 15:48
7 lines
1088 bytes
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
Re: Javascript template for cs4 needed
#138
Author: christoph_pfaffenbichler
Date: Sun, 15 Mar 2009 13:35
5 lines
1117 bytes
You�re welcome.

But I must admit I cut two corners:
Firstly I didn�t 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.
Re: Javascript template for cs4 needed
#139
Author: Paulo_Skylar
Date: Sun, 15 Mar 2009 15:56
5 lines
1192 bytes
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
Re: Javascript template for cs4 needed
#140
Author: christoph_pfaffenbichler
Date: Sun, 15 Mar 2009 16:32
8 lines
1399 bytes
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 Layer�s:
"app.activeDocument.layers["the group�s 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 LayerSet�s child, meaning one has to address it not as "app.activeDocument.layers["the layer�s name or index"]" but "app.activeDocument.layers["the group�s name or index"].layers["the layer�s 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?
Re: Javascript template for cs4 needed
#219
Author: Paulo_Skylar
Date: Fri, 20 Mar 2009 16:26
6 lines
1197 bytes
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
Re: Javascript template for cs4 needed
#223
Author: christoph_pfaffenbichler
Date: Sat, 21 Mar 2009 09:08
3 lines
831 bytes
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.
Re: Javascript template for cs4 needed
#226
Author: Paulo_Skylar
Date: Sat, 21 Mar 2009 15:38
4 lines
691 bytes
Great, I think the solution for my problem is coming into focus.
Thanks again,

Paulo
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads