Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
thank you
Copy link to clipboard
Copied
Works perfectly, thanks!
Copy link to clipboard
Copied
how would you make a prompt alerting you that hidden layers have been found
and if you press ok they will be deleted if you press cancel it will close out the script with no change?
Copy link to clipboard
Copied
This script searches for invisible layers and asks the user if they should be removed.
doc = app.activeDocument;
invisibleLayers = new Array;
layers = doc.layers;
//collect invisible layers
for (i = 0; i < layers.length; i++)
{
if (layers.visible == false)
{
invisibleLayers.push(layers);
}
}
//when no invisible layers are found prompt alert and exit
if (invisibleLayers.length == 0) {alert("No invisible layers have been found."); exit();}
//when invisible layers are found ask user if they should be removed
if (invisibleLayers.length > 0)
{
x = confirm(invisibleLayers.length + " invisible Layers have been found.\nDo you want to delete them?");
}
//exit script when users clicks "no"
if (x == false) {exit();}
//remove layers when user clicks "yes"
for (i = invisibleLayers.length-1; i >= 0; i--)
{
invisibleLayers.remove();
}
Copy link to clipboard
Copied
thank you....this was working great until we encountered mission creep
they changed the mission to now have this incorporated into a larger script so instead of closing out the script when the user presses no, it just passes thru and continues on with the next step of the script without doing anything.
i tried this...but get an error (sometimes?) at if (x == true)
doc = app.activeDocument;
invisibleLayers = new Array;
layers = doc.layers;
//collect invisible layers
for (i = 0; i < layers.length; i++)
{
if (layers.visible == false)
{
invisibleLayers.push(layers);
}
}
//when no invisible layers are found prompt alert and exit
//*****if (invisibleLayers.length == 0) {alert("No invisible layers have been found."); exit();}
//when invisible layers are found ask user if they should be removed
if (invisibleLayers.length > 0)
{
x = confirm(invisibleLayers.length + " invisible Layers have been found.\nDo you want to delete them?");
}
//exit script when users clicks "no"
if (x == true)
for (i = invisibleLayers.length-1; i >= 0; i--)
{
invisibleLayers.remove();
}
Copy link to clipboard
Copied
Hi Js1212,
I think the problem is that the loop needs to be put in curly brackets
//if user clicks "yes": delete invisible Layers
if (x == true)
{
for (i = invisibleLayers.length -1; i >= 0; i--)
{
invisibleLayers.remove();
}
}
Greetings
Copy link to clipboard
Copied
Put the following statement before the if where you are showing the prompt
var x = false
The issue is that in case there is no layer which is invisible, x remains undefined and the condition x == true results in error
-Manan
Copy link to clipboard
Copied
Hi,
The curly brackets are not needed as by default one statement is covered
-Manan
Copy link to clipboard
Copied
much appreciated....you made me look like a rockstar!!!!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more