Copy link to clipboard
Copied
new to scripting... please help! I have this script:
app.activeDocument.save();
var myWaterLayerName = "Draft";
try{app.activeDocument.layers.item(myWaterLayerName).visible = false;}
catch(_){alert("Can't find layer: " + myWaterLayerName);exit();};
that hides a layer in the active document. how can i modify to work on all open documents?
Hi Malcom,
you need no loop because you can work with the collection of documents:
app.documents.everyItem().layers.itemByName("Draft").visible = false;
This is working even if some of the documents do not contain a layer named "Draft".
getElements() will give you an array. Because of that you have to loop.
Regards,
Uwe
Copy link to clipboard
Copied
[ moved from InDesign to InDesign Scripting ]
Copy link to clipboard
Copied
Hello!
I am new at scripting as well, but I think I’ve come up with a solution for you. The script may take a while to run if you have a lot of documents open.
Try the code below.
var myWaterLayerName = "Draft";
for(myCounter = app.documents.length;
myCounter > 0;
myCounter--){
try{
app.documents.item(myCounter-1).layers.item(myWaterLayerName).visible = false;
app.documents.item(myCounter-1).save();
}
catch(_){alert("Can't find layer: " + myWaterLayerName);exit();};
}
Copy link to clipboard
Copied
Hi,
a similar but simpler script to do the job,
var toHideLayers = app.documents.everyItem().layers.itemByName("Draft").getElements();
for ( var i = 0; i < toHideLayers.length; i++)
{
toHideLayers.visible = false;
}
This will get the layer called "Draft" from every open document.
Hope this helps.
Malcolm
Copy link to clipboard
Copied
Hi Malcom,
you need no loop because you can work with the collection of documents:
app.documents.everyItem().layers.itemByName("Draft").visible = false;
This is working even if some of the documents do not contain a layer named "Draft".
getElements() will give you an array. Because of that you have to loop.
Regards,
Uwe
Copy link to clipboard
Copied
thanks! this is working perfectly! Much appreciated.
Copy link to clipboard
Copied
Of course, don't know how I didn't see that.
Regards
Malcolm
Copy link to clipboard
Copied
thanks everyone for the help!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now