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
// 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")}
}
};
(aL=(aD=activeDocument).activeLayer) == (lrs=aL.parent.layers)[lrs.length - 1]
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.
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.
Copy link to clipboard
Copied
With "first" I mean if it is the top layer inside the Group or not.
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")}
}
};
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.
Copy link to clipboard
Copied
That should be possible with layers.length
Copy link to clipboard
Copied
(aL=(aD=activeDocument).activeLayer) == (lrs=aL.parent.layers)[lrs.length - 1]