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

my first "for loop" doesn't work.

LEGEND ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

Why doesn't it? It deletes all but one hidden item on the targeted layer then errors here: "if (bkItem.hidden == true){" with "no such element"'.

var aDoc = app.activeDocument;

var bkItem = aDoc.layers["BACK TEXT"].pageItems;

var bkCnt = bkItem.length;//# of items in "BACK TEXT"

var a;//counter

for (a=0; a<bkCnt; a++){

    if (bkItem.hidden == true){

        bkItem.remove();

     }

  }

TOPICS
Scripting

Views

423

Translate

Translate

Report

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 05, 2019 Jun 05, 2019

loop backwards

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

loop backwards

Votes

Translate

Translate

Report

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
LEGEND ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

Thanks, pixxxel schubser​

This worked for me. The other key was adding a "=" to the if statement (a = bkCnt - 1; a >= 0; a--).

var aDoc = app.activeDocument;

var bkItem = aDoc.layers["BACK TEXT"].pageItems;

var bkCnt = bkItem.length;//# of items in "BACK TEXT"

var a;//counter

for (a = bkCnt - 1; a >= 0; a--){

    if(bkItem.hidden == true){

        bkItem.locked = false;

        bkItem.remove();

     }

}

Votes

Translate

Translate

Report

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 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

LATEST

Yes, because of pageItems[0] is the first pageItem in the "object array".

This also should also work:  a> -1

Votes

Translate

Translate

Report

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