Copy link to clipboard
Copied
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?
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
Copy link to clipboard
Copied
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 );
};
Copy link to clipboard
Copied
Thank you sir.
Copy link to clipboard
Copied
is there a way to do this so that it turn all layers 'ON' instead of 'off' ?
Copy link to clipboard
Copied
function showAllLayers() {
var numberOfLayers = getNumberOfLayer();
var desc = new ActionDescriptor();
var list1 = new ActionList();
var ref = new ActionReference();
for(var layerIndex=1-Boolean(hasBackground());layerIndex<=numberOfLayers;layerIndex++){
ref.putIndex( charIDToTypeID('Lyr '), layerIndex );
}
list1.putReference( ref );
desc.putList( charIDToTypeID('null'), list1 );
executeAction( charIDToTypeID('Shw '), desc, DialogModes.NO );
};
function getNumberOfLayer(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
var numberOfLayer = desc.getInteger(charIDToTypeID("NmbL"));
return numberOfLayer;
};
function hasBackground(){
var res = undefined;
try{
var ref = new ActionReference();
ref.putProperty( 1349677170 , 1315774496);
ref.putIndex( 1283027488, 0 );
executeActionGet(ref).getString(1315774496 );;
res = true;
}catch(e){ res = false}
return res;
};
showAllLayers();
Find more inspiration, events, and resources on the new Adobe Community
Explore Now