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

Active and current layer

Engaged ,
Nov 30, 2015 Nov 30, 2015

Copy link to clipboard

Copied

Hello,

When looping over layers, what is the best way to:

1. Get the "active" layer?

2. Set a new layer as active?

Also, is there an easy way to get the index of the app.activeDocument.activeLayer when not looping over layers? In other words, can I determine the activeLayer's index without using a loop to find it?

Thanks!

TOPICS
Scripting

Views

688

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

Valorous Hero , Dec 01, 2015 Dec 01, 2015

Setting the activeLayer property does the setting trick:

    doc.activeLayer = doc.layers[1];

And getting the index seems to work using the zOrderPosition property for getting the 1-based stacking order:

    alert(doc.activeLayer.zOrderPosition); // 2

Votes

Translate

Translate
Adobe
Valorous Hero ,
Dec 01, 2015 Dec 01, 2015

Copy link to clipboard

Copied

Setting the activeLayer property does the setting trick:

    doc.activeLayer = doc.layers[1];

And getting the index seems to work using the zOrderPosition property for getting the 1-based stacking order:

    alert(doc.activeLayer.zOrderPosition); // 2

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
Engaged ,
Dec 01, 2015 Dec 01, 2015

Copy link to clipboard

Copied

LATEST

Awesome! Thanks Silly-V‌!

I can't believe I didn't think to set the activeLayer like that. It's so obvious now that you point it out. Lol.

+1 on the zOrderPosition. I saw that in the object viewer, but I wasn't sure if that was a reliable way to get the index. Much appreciated!

Also, for future readers, one way to check for active layer when looping over layers is:

_doc = app.activeDocument;

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

  current = _doc.layers;

  if (current === _doc.activeLayer) {

  // The `current` layer is the `activeLayer`, so do something.

  }

}

Thanks a billion Silly-V‌, I totally appreciate all of your pro help!

Have a great week!


Cheers,

M

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