Copy link to clipboard
Copied
This should be fairly easy, I have tried to make one myself, but haven't gotten it right yet.
What I need to accomplish:
Have a script delete Layers by name, even if locked / hidden / have sublayers with art.
Example Layers:
Anchor Point
Center guides
Original
Also something not case sensitive would be preferable.
I started by just repeating this "app.activeDocument.layers.getByName('Anchor Point').remove();" with the different layers typed in, but it errors out when it tries to remove a layer that's not there in the specific file.
1 Correct answer
Hi, Xenoit!
Try to use that construction:
try {
var layToRm = activeDocument.layers.getByName('Anchor Point');
if(!layToRm.visisible) layToRm.visible = true;
if(layToRm.locked) layToRm.locked = false;
layToRm.remove();
} catch (e) {}
It works only on top layers.
If you want to remove a sublayers too, then you need make recursive function...
Explore related tutorials & articles
Copy link to clipboard
Copied
Hi, Xenoit!
Try to use that construction:
try {
var layToRm = activeDocument.layers.getByName('Anchor Point');
if(!layToRm.visisible) layToRm.visible = true;
if(layToRm.locked) layToRm.locked = false;
layToRm.remove();
} catch (e) {}
It works only on top layers.
If you want to remove a sublayers too, then you need make recursive function...
Copy link to clipboard
Copied
if(!layToRm.visible) *****
just wanted to point out the typo in line 3 in case anyone tries to copy and paste this into ESTK
Copy link to clipboard
Copied
Awesome, I'll try that out shortly! Thanks for the quick replies guys!
Copy link to clipboard
Copied
Yes, this is exactly what I wanted, thank you so much o-marat & williamadowling for catching that typo!

