Copy link to clipboard
Copied
With the help of this forum I obtained a script which toggles the visibility of a specific layer without selecting the layer.
I would like to find out if the same functionality can be achieved for a layer group.
In other words can script toggle the visibility of a layer group with out actually selecting the layer group?
I understand some parts of Photoshop are not scriptable and wan to make sure this isn't one of them before I embark in creating the script.
I have a script that does what you need. Can't remember if I obtained it from here, but I do know that the scripting guys in here are geniuses and can help you out with almost anything. That said, here is the script that you need. All you need to do is replace the three "Insert Layer Name Here" portions with the name of the layer you wish to toggle on/off. Don't thank me, thank whoever wrote it, (most likely someone here)
...var targetID = getLayerIDByName('Insert Layer Name here');
if(undefin
Copy link to clipboard
Copied
As far as AM code is concerned Groups are Layers, too, so what is the problem?
Copy link to clipboard
Copied
No problem at all. Trying to figure out an approach to create the script.
I can get the AM code from the script listener for the layer group visibility toggle.
Make a function with the AM code, declare a variable for the layer group,
use an if statement to check the visibility of the layer group.
If visibility is true then do the opposite.
Copy link to clipboard
Copied
And if you're talking Javascript, you have the LayerSet.visible for that. Just remember you have multiple ways of going through a document
Copy link to clipboard
Copied
Thanks for the clarification. I looked up the layer groups in the object document model and found the terminology for a layer group confusing.
Copy link to clipboard
Copied
I have a script that does what you need. Can't remember if I obtained it from here, but I do know that the scripting guys in here are geniuses and can help you out with almost anything. That said, here is the script that you need. All you need to do is replace the three "Insert Layer Name Here" portions with the name of the layer you wish to toggle on/off. Don't thank me, thank whoever wrote it, (most likely someone here)
var targetID = getLayerIDByName('Insert Layer Name here');
if(undefined != targetID){
if(getLayerVisibilityByID( targetID ) ){
hideByName('Insert Layer Name here');
}else{
showByName('Insert Layer Name here');
}
}
function getLayerIDByName(name) {
try{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "LyrI" ));
ref.putName( charIDToTypeID( "Lyr " ), name );
return executeActionGet(ref).getInteger(charIDToTypeID( "LyrI" ));
}catch(e){}
};
function getLayerVisibilityByID( id ) {
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "Vsbl" ));
ref.putIdentifier( charIDToTypeID( "Lyr " ), id );
return executeActionGet(ref).getBoolean(charIDToTypeID( "Vsbl" ));
};
function hideByName(name) {
var desc = new ActionDescriptor();
var list = new ActionList();
var ref = new ActionReference();
ref.putName( charIDToTypeID('Lyr '), name );
list.putReference( ref );
desc.putList( charIDToTypeID('null'), list );
executeAction( charIDToTypeID('Hd '), desc, DialogModes.NO );
};
function showByName(name) {
var desc = new ActionDescriptor();
var list = new ActionList();
var ref = new ActionReference();
ref.putName( charIDToTypeID('Lyr '), name );
list.putReference( ref );
desc.putList( charIDToTypeID('null'), list );
executeAction( charIDToTypeID('Shw '), desc, DialogModes.NO );
};
EDIT- whoops, I just realized this is only for layers, not groups. But hopefully it's a starting point
Copy link to clipboard
Copied
No worries, I realize it was for layer when I skimmed the script. Strangely enough it works with layer groups also.
Thanks!
Copy link to clipboard
Copied
This script is works perfect but toggles only the first layer with specific name. Is there any possibility to toggle ALL the layers with this specific name?
Copy link to clipboard
Copied