Skip to main content
Participating Frequently
June 3, 2011
Question

isolating a layer (hiding all other layers)

  • June 3, 2011
  • 1 reply
  • 1199 views

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.

This topic has been closed for replies.

1 reply

Known Participant
June 3, 2011

Do you know the layer name(s) that you want to show?

Participating Frequently
June 4, 2011

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.

c.pfaffenbichler
Community Expert
Community Expert
June 4, 2011

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 );