Skip to main content
January 9, 2013
Answered

Selecting Only Visible Layers

  • January 9, 2013
  • 1 reply
  • 1244 views

I am a beginner scripter trying to find a way to hide all the layers in a document.  The document has hundreds of layers so selecting all and then hiding all takes way too long to run.  Is there a way to simlply hide all or select only the layers that are visible and then hide?

This topic has been closed for replies.
Correct answer Paul Riggott

Here is one way to turn all layers visibility off ...

//select top layer

activeDocument.activeLayer = activeDocument.layers[0];

//toggle all other layers visibility off

toggleVisability();

//toggle this layers visibility off

activeDocument.activeLayer.visible=false;

//This function is the same as Alt/Click on a layers eye

function toggleVisability() {

var desc = new ActionDescriptor();

var list1 = new ActionList();

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') );

list1.putReference( ref );

desc.putList( charIDToTypeID('null'), list1 );

desc.putBoolean( charIDToTypeID('TglO'), true );

executeAction( charIDToTypeID('Shw '), desc, DialogModes.NO );

};

1 reply

Paul Riggott
Paul RiggottCorrect answer
Inspiring
January 9, 2013

Here is one way to turn all layers visibility off ...

//select top layer

activeDocument.activeLayer = activeDocument.layers[0];

//toggle all other layers visibility off

toggleVisability();

//toggle this layers visibility off

activeDocument.activeLayer.visible=false;

//This function is the same as Alt/Click on a layers eye

function toggleVisability() {

var desc = new ActionDescriptor();

var list1 = new ActionList();

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') );

list1.putReference( ref );

desc.putList( charIDToTypeID('null'), list1 );

desc.putBoolean( charIDToTypeID('TglO'), true );

executeAction( charIDToTypeID('Shw '), desc, DialogModes.NO );

};

January 9, 2013

Thank you sir.

Inspiring
August 18, 2013

is there a way to do this so that it turn all layers 'ON' instead of 'off' ?