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

Script run for multi layer same name

Participant ,
Jun 14, 2018 Jun 14, 2018

Copy link to clipboard

Copied

I have a script

function doesLayerExist(layers, name) {

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

        if (layers.name==name) return true;

    }

    return false;

}

if (doesLayerExist(app.activeDocument.layers, "MTN")) {

    // command

}

But it run for one layer name "MTN", not run for multi layer name "MTN".

Please help me fix it.

Thank in advance!!!

TOPICS
Actions and scripting

Views

774

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

LEGEND , Jun 15, 2018 Jun 15, 2018

In your code when loop in function finds first 'MTN' layer it returns result and function is stopped. Try this:

len = (lyrs = activeDocument.layers).length

for(i = 0; i < len; i++) {

    if (lyrs.name == 'MTN') alert(true)

}

Votes

Translate

Translate
Adobe
LEGEND ,
Jun 15, 2018 Jun 15, 2018

Copy link to clipboard

Copied

In your code when loop in function finds first 'MTN' layer it returns result and function is stopped. Try this:

len = (lyrs = activeDocument.layers).length

for(i = 0; i < len; i++) {

    if (lyrs.name == 'MTN') alert(true)

}

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
Participant ,
Jun 15, 2018 Jun 15, 2018

Copy link to clipboard

Copied

thank for helpful!

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
People's Champ ,
Jun 15, 2018 Jun 15, 2018

Copy link to clipboard

Copied

What are you really going to do instead of

// command

?

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
Participant ,
Jun 15, 2018 Jun 15, 2018

Copy link to clipboard

Copied

LATEST

something, example: bright up for all layer name "MTN"

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