Copy link to clipboard
Copied
I have started writing my first script but I am struggling to find out how to isolate an active layer.
Part of my script reads;
var doc = app.activeDocument;
doc.activeLayer = doc.artLayers.getByName('mk stone');
at this point I would like to hide all other layers in the document. I will then select one of the RGB channels then unhide the other layers.
I have worked out the selection part. So all I really need to know is how to hide and unhide all other layers.
Any help would be much appreciated.
Copy link to clipboard
Copied
Do you know the layer name(s) that you want to show?
Copy link to clipboard
Copied
There will be a number of layers to turn on and off.
The way it works is to create a folder and select a layer with the corresponding name. i.e create a new layerset called "stone set", then select an existing layer in the scene, this would be called "mk stone".
I would then select an individual RBG channel, load the selection and then make the "stone set" the active layer and apply the layer mask to the layerset.
I have got all this working fine. The only problem is when I try it with more than one layer because it just keeps seeing the highest up layer in the stack and reapplying these selections to all layersets.
I need to tell it to make "mk stone" the only layer shown, make a RGB selection and then return back to the previous visibilty state. I would then apply the layer mask as previously mentioned select another layer "mk brick" hide all other layers make the RGB selection return to the previous visibilty state apply layer mask to the layerset etc....
It would be alot better if it could return to a previous visibilty state as some files I use have certain layers/layersets turned off and would be useful not to turn all these back on. If not I could work in an external file, but ideally in the same. What I really need is exactly the same as 'alt' clicking the the eye icon on a layer and 'alt' clicking to return to the previous state.
Hope this makes sense. Many thanks for any help.
Copy link to clipboard
Copied
if the layer in question is active you could try (and run it afterwards again to show the other layers again):
// =======================================================
var idShw = charIDToTypeID( "Shw " );
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list1 = new ActionList();
var ref3 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref3.putEnumerated( idLyr, idOrdn, idTrgt );
list1.putReference( ref3 );
desc4.putList( idnull, list1 );
var idTglO = charIDToTypeID( "TglO" );
desc4.putBoolean( idTglO, true );
executeAction( idShw, desc4, DialogModes.NO );
Copy link to clipboard
Copied
Hi c.pfaffenbichler,
I had played around with the Scriptlistener Plugin and got the same code. Only the first time I gave up with it not knowing what to do with the code. It was after you giving the same code that I thought it must be right and played around with it until putting it into a function. Slowly learning new bits hear and there and always grateful for a little help a long the way,
Thanks again.
Copy link to clipboard
Copied
To hide all layers but the selected layer.
// hide all layers
for(var i=0; i<doc.layers.length; i++){
doc.layersvisible = false;
}
var mkStoneLayer= doc.artLayers.getByName('mk stone');
mkStoneLayer.visible = true;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now