I’m hoping someone knows how to script in photoshop, as I’m hoping someone could do me a favor ?
Photoshop is an image editor, not a code editor. What are you trying to do?
Here’s a site dedicated to Photoshop Scripting. It has a forum.
Photoshop is an image editor, not a code editor. What are you trying to do?
Trying to find someone who could script a little automated task for me, for free
Victorinox - I’m going to try that site, I came across it a few days ago but didn’t feel I would make any progress, but I’ll try this time around
Describe the task here in the topic and maybe someone will give it a go.
As it’s for free it’s only fair that the results should be freely available for others to see.
I broke it down into two parts. Since it’s free if someone finds it useful I have no problems with that
- When I create a new document, and I create a specific set of up to 5 groups each with a specific name, each of those five groups photoshop would automatically, know which specific keyboard short cuts assigned to each of the groups, since it would know when those groups are created assigned these keyboard short cuts. When I hit that keyboard short cut all other groups/layers visibility is turned off, except for that one group which I triggered with it’s own specific keyboard shortcut. If all 5 groups are in the photoshop document then hitting each keyboard shortcut for each group, would turn off all other groups/layers.
- For saving purposes, set suppose I have Acme1, Acme2, Acme3, Acme4, Acme5 and Acme1 has a keyboard short cut of 1, Acme2 has a keyboard short cut of 2 etc. When I hit the keyboard shortcut 2, all other group visibility is turned off. When I go and save the file photoshop would add, automatically know that for the group Acme2 to add an underscore followed by Acme2.PSD as in _Acme2.PSD (although the group names would be different then Acme) All I would have to do is type in the file name I want <filename> and photoshop would add the group name extension as in <filename>_Acme2.PSD, based on that is the only group with it’s visibility that is ON.
I could give it a try but depends on what you want. I am not very experienced with Photohsop scripting but I do have a terrific manual about it.
Doesn’t Photoshop provide this already? If you hold down Alt and click the visibility icon of a Group, all other Groups will be hidden.
I could give it a try but depends on what you want. I am not very experienced with Photohsop scripting but I do have a terrific manual about it.
If you would like to give it a try, I would appreciate it.
Doesn’t Photoshop provide this already? If you hold down Alt and click the visibility icon of a Group, all other Groups will be hidden.
Photoshop, can’t create groups and toggle other groups on or off based on keyboard short-cuts
You didn’t specify that the script needed to create groups.
From your description it sounds as if you could simply save a template document with the groups set up in it.
The shortcut I described works if one can use a mouse. Is there a physical reason preventing you pointing and clicking?
No keyboard short-cuts for the groups. It’s mostly an automated script, I explained it
I think that you need to investigate Layer Comps and Smart Objects.
Layer Comps allow you to store away different types of layer settings, while smart object allow you to use separate external files as a layer object.
This is not Photoshop (this is Sparta?) but is the JavaScript forum which hardly ever gets to deal with Photoshop. You may instead want to visit a Photoshop forum where the denizens will have much more knowledge on how to script Photoshop.
That is what I’m going to do. I already know about layer comps etc, this is more automated, as I had mentioned.
I think I have your script. Due to personal reasons I will not be around for the next two days, I think, so I am sorry for the delay and if this causes any trouble. Just posting to keep you informed. I have a few questions about what it needs to be done but… I thing I have understood it well enough and that I have what you want… more or less.
Oh, thank you very much. I can wait (2) days when you are back just notify me in some way and I can answer your questions and test out the script.
Sorry for the delay. It is not finished, but it is a start.
I have to say that Photoshop is quite complicated. Although I used JavaScript because then the script can be used in both Macintosh and Windows computers, it just doesn’t work properly and I can’t understand why.
The first part only hides the layers except for the one chosen:
var docRef=app.activeDocument;
var acme1 =docRef.layers.getByName("nameOfLayer");
selectAllLayers();
hideLayers();
acme1.visible=true;
function selectAllLayers() {
var ref = new ActionReference();
ref.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
var desc = new ActionDescriptor();
desc.putReference(cTID('null'), ref);
executeAction(sTID('selectAllLayers'), desc, DialogModes.NO);
}
function hideLayers() {
var ref = new ActionReference();
ref.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
var list = new ActionList();
list.putReference(ref);
var desc = new ActionDescriptor();
desc.putList(cTID('null'), list);
executeAction(cTID('Hd '), desc, DialogModes.NO);
}
function cTID(s) {return app.charIDToTypeID(s);}
function sTID(s) {return app.stringIDToTypeID(s);}
First I added two more variables and used a simple for iterative structure to hide all the layers except the one I wanted visible:
var layerCount=docRef.layers.length;
var allLayers = docRef.layers;
for(i=0;i < layerCount; i++){
if(allLayers[i].name!=acme1.name){
allLayers[i].visible=false;
}
}
It worked fine as the layers collection includes both artLayers (or layers with text or graphics, normal layers) and layerSets.
It was terribly slow though. It took ages. I found a site where there was a script that hid all the layers (http://morris-photographics.com/photoshop/scripts/hide-layers.html) so I copied that part of the code and used it. It was much faster.
Then, I made visible the layer (or layerSet) I was interested in.
I found two options to save the file but I have not been very lucky to make them work (and this is the part that I don’t understand).
The first has to do with a script already available in Photoshop (File > Scripts > Export Layers to File) which has an option to save in different formats, including PSD, and you can choose between saving all layers or only those that are visible.
Since I was not very lucky, I thought to do it the simpler way:
function saveLayers(){
for( var i = 0; i < allLayers.length; i++) {
if(!allLayers[i].visible){
docRef.layers[i].remove();
}
}
psdFile = new File( "_"+acme1.name+".psd" );
psdSaveOptions = new PhotoshopSaveOptions();
docRef.saveAs(psdFile,psdSaveOptions, false, Extension.LOWERCASE);
}
The part that doesn’t work is deleting the invisible layers. No matter how I do it (even if I compare the layers name), for some reason it deletes all the layer except for the layer background, therefore it can’t save the file because the layer that was supposed to remain doesn’t exist anymore.
Don’t know how to asign it to a keyboard shortcut yet although I suspect that the script will have to be loaded as an event script to do that.
Molona - I will test it out soon, as I’m to head out the door in a short while. I will reply more then let me know if there are updates
I may have overlooked but did you mention that you are still finding a way for the script to toggle off the layers and assign keyboard short cuts for specific group names ?
You should create a Layer Comp instead and then use scripting to activate just that comp. It’s much faster and efficient than coding up all of the changes by hand.
I tried to use Layer Comp but the result wasn’t as expected. I would have expect that only the layers visible would be saved, but instead it saved all the layers and simply left those that were invisible, invisible and those that were visible, visible. So, again, you have to remove them somehow.
Molona - Remember you want to hide the layers not remove them. I can enter in the script the (5) groups, and each group name would have a keyboard short cut. For example if I have (5) groups labeled:
Cat (keyboard short cut T)
Mouse (keyboard short cut H)
Ball (keyboard short cut Y)
Dog (keyboard short cut P)
Roller (keyboard short cut F)
When when I hit the H on the keyboard all the other layer groups visibility is turned OFF same goes for the other groups etc, etc.
You understand about the saving, so if I have only the layer group called MOUSE visibility ON and I want to save that it would add the group name automatically to the file name in other words MOLONAGRAPHIC_MOUSE.PSD which you already understand
Can all the individual script files be combined into (1) script, I know the script is not finished yet but when it is, because the script is broken up now, am I correct ?
Remember to make it an option to change the GROUP names and the keyboard short cuts in the script