Skip to main content
Xenoit
Participating Frequently
February 21, 2017
Answered

Delete Multiple Layers via Script

  • February 21, 2017
  • 1 reply
  • 8527 views

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.

This topic has been closed for replies.
Correct answer o-marat

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...

1 reply

o-marat
o-maratCorrect answer
Inspiring
February 21, 2017

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...

Disposition_Dev
Legend
February 21, 2017

if(!layToRm.visible) *****

just wanted to point out the typo in line 3 in case anyone tries to copy and paste this into ESTK

Xenoit
XenoitAuthor
Participating Frequently
February 21, 2017

Awesome, I'll try that out shortly!  Thanks for the quick replies guys!