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

Question regarding the object model, specifically regarding [Layers] vs [GroupItems]

Guide ,
Jun 13, 2020 Jun 13, 2020

Copy link to clipboard

Copied

The guide states that "the layer and group item classes can contain nested objects of the same class which can, in turn, contain additional nested objects".

 

Untitled666.png

 

So I understand why I use recursion to iterate over nested layers.

 

But I can iterate over all groupItems, including nested groupItems, directly without recursion.  (I presume that "child" groupItems are added to the "parent" groupItems collection.)

 

My question is: Why the difference?

 

Thanks in advance.

 

Untitled667.png

 

var theLayers = activeDocument.layers;
var theList = "";
for (var i = 0; i < theLayers.length; i++) {
  theList = theList + theLayers[i].name + "\r";
}
alert(theList);//Layer 1 Layer 2 (i.e. parent layers only)
var theItems = activeDocument.groupItems;
var theList = "";
for (var i = 0; i < theItems.length; i++) {
  theList = theList + theItems[i].name + "\r";
}
alert(theList);//A1 A2 A2a A2a1 (i.e. parent and child groupItems)

 

TOPICS
Scripting

Views

310

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 14, 2020 Jun 14, 2020

Hi, I don't know the reason why it works the way you described, but I'm glad it does. The more options we have the better for us. The currrent behaviour comes in very handy at times.

 

If you only want to target top levels groups (excluding nested groups) loop through layers, then through groups in each layer.

 

At the document level, every groupItem is available wheter is nested or not. It's the same behaviour other pageItems have. But I hear you, layers/sublayers have their own logic.

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 14, 2020 Jun 14, 2020

Copy link to clipboard

Copied

LATEST

Hi, I don't know the reason why it works the way you described, but I'm glad it does. The more options we have the better for us. The currrent behaviour comes in very handy at times.

 

If you only want to target top levels groups (excluding nested groups) loop through layers, then through groups in each layer.

 

At the document level, every groupItem is available wheter is nested or not. It's the same behaviour other pageItems have. But I hear you, layers/sublayers have their own logic.

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