Skip to main content
Zesty_wanderlust15A7
Known Participant
May 18, 2021
Answered

PS script needed for 'if NOT first child in a group'

  • May 18, 2021
  • 1 reply
  • 1163 views

I know how to check if my selected layer is inside a group (parent).

 

Now I would like to know how to check if that layer is the first layer (child) in that group (or if it is not).

 

Dug through some stuff, but I'm afraid I may get overly complicated... 🙂

 

TIA

Correct answer Kukurykus

Thanks c.p! 🙂

As often happens, I didn't test well enough and it turns out I needed a check for the LAST layer, not the first...

Then I realized I could use a DUMMY layer to prevent needing a script at all, so I did that.

I'm taking note anyway, as it has come into my wishlist often before.

 

Is a check for last layer very simple?  If not, don't bother for now.


 

(aL=(aD=activeDocument).activeLayer) == (lrs=aL.parent.layers)[lrs.length - 1]

 

1 reply

JJMack
Community Expert
May 18, 2021

The first in the group?  If you target three layers and create a group from the layer which is the first in the group the bottom layer in the group the top layer  in the group? You can process the layer stack see the stacking order, see layer kind,  id, name, parent, bounds, etc.  Layer groups can be nested. So you can create Lists of  layer in a layer group in the stacking order in the group. However, between layers in a layer group the can nested layer groups. So some layers and some layer groups can have the document be their other layers and layer groups can have other layer groups parents.

JJMack
Zesty_wanderlust15A7
Known Participant
May 18, 2021

Yes, to know if it's the first (or NOT the first).

I will select a layer and different actions can put a different mask on it. Because of how I do that, there are several circumstances I have to watch out for.

My code will already know if I'm inside a Group or not. If I am, I have to know if my chosen layer was the first inside the group or another one — otherwise the mask may appear on the wrong layer...

 

I don't care about invisible layers or if it is a nested Group layer. That will hardly ever occur.

Zesty_wanderlust15A7
Known Participant
May 18, 2021

With "first" I mean if it is the top layer inside the Group or not.