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

Loop and Delete Artboards

Participant ,
Jun 23, 2016 Jun 23, 2016

Need some help.  Trying to loop through artboards and delete if not a specific name.  When trying to remove it gives me an illegal argument.  I must be missing something.  Help would be appreciated.

var idoc = app.activeDocument; 

var artbs = idoc.artboards;

var artbcount = artbs.length;

var artbsNames = [];

for (var i=0; i< artbcount; i++) {  

    artbsNames = artbs.name;

     var artboardSelected = idoc.artboards;

     artboardSelected = artbsNames;

    if (artboardSelected == ["Special Artboard"]) {

      alert("This is not Special");

      }

    else {

        artbs.remove();

        }

TOPICS
Scripting
1.0K
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

Community Expert , Jun 23, 2016 Jun 23, 2016

Hi jeremy0013

Why so complicated? Like Silly-V​ said: if you want to remove an item of your loop you have loop backwards always.

And a simple if clause should be enough:

var idoc = app.activeDocument;

var artbs = idoc.artboards;

for (var i = artbs.length-1 ; i >= 0; i--) {

    if (artbs.name != "Special Artboard") {

        artbs.remove();

    }

}

Does this works for you?

Have fun

Translate
Adobe
Valorous Hero ,
Jun 23, 2016 Jun 23, 2016

it should be artbs

* and I would go through anything you remove, backwards for safety.

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
Participant ,
Jun 23, 2016 Jun 23, 2016

Thanks V.  Still having issue though.  It only deletes 2 of the 3 that are named special.  Revised code.

var idoc = app.activeDocument;

var artbs = idoc.artboards;

var artbsNames = [];

for (var i=0; i< artbs.length; i++) { 

    artbsNames = artbs.name;

    if (artbsNames == ["Special Artboard"] ) {

      artbs.remove();

      }

}

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 ,
Jun 23, 2016 Jun 23, 2016

Hi jeremy0013

Why so complicated? Like Silly-V​ said: if you want to remove an item of your loop you have loop backwards always.

And a simple if clause should be enough:

var idoc = app.activeDocument;

var artbs = idoc.artboards;

for (var i = artbs.length-1 ; i >= 0; i--) {

    if (artbs.name != "Special Artboard") {

        artbs.remove();

    }

}

Does this works for you?

Have fun

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
Participant ,
Jun 23, 2016 Jun 23, 2016
LATEST

I get what V ment now about moving backwards.  Still learning.  I know the first code was way complicated, this one works perfect.  Thanks 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