Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Delete Multiple Layers via Script

Community Beginner ,
Feb 20, 2017 Feb 20, 2017

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.

TOPICS
Scripting
8.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Feb 20, 2017 Feb 20, 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...

Translate
Adobe
Engaged ,
Feb 20, 2017 Feb 20, 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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2017 Feb 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 21, 2017 Feb 21, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 21, 2017 Feb 21, 2017
LATEST

Yes, this is exactly what I wanted, thank you so much o-marat​ & williamadowling​ for catching that typo!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines