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

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

Advocate ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

866

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 2 Correct answers

Community Expert , May 18, 2021 May 18, 2021
// 2021, use it at your own risk;
if (documents.length > 0) {
var theDocument = activeDocument;
var theLayer = theDocument.activeLayer;
var theParent = theLayer.parent;
if (theParent.typename == "LayerSet") {
    if (theLayer == theParent.layers[0]) {alert ("first")}
    else {alert ("not first")}
}
};

Votes

Translate

Translate
LEGEND , May 18, 2021 May 18, 2021

 

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

 

Votes

Translate

Translate
Adobe
Community Expert ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

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.

image.png

JJMack

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
Advocate ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

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.

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
Advocate ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

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

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 ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

// 2021, use it at your own risk;
if (documents.length > 0) {
var theDocument = activeDocument;
var theLayer = theDocument.activeLayer;
var theParent = theLayer.parent;
if (theParent.typename == "LayerSet") {
    if (theLayer == theParent.layers[0]) {alert ("first")}
    else {alert ("not first")}
}
};

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
Advocate ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

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.

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 ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

That should be possible with layers.length 

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 ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

LATEST

 

(aL=(aD=activeDocument).activeLayer) == (lrs=aL.parent.layers)[lrs.length - 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