Yes, I still used API v 1.
But require("photoshop").app.activeDocument.activeLayers[0] should still work (I assume only one layer is selected and this one you like to check).
I don’t think you need to check the kind – just that if parent is anything other than undefined.
So:
if (app.activeDocument.activeLayers[0].parent) {
console.log("Layer is in a group")
} else {
console.log("Layer is not in a group")
}
Having kind here should be superfluous – it would always be group, because parent.kind can only exist for groups.
(Side note)
You’re running into fun JavaScript territory where property access on undefined results in these kinds of funny errors. You could use the ?. operator to manage this:
if (app.activeDocument.activeLayers[0].parent?.kind === "group") /* ... */
But in this case, that’s superfluous, since the kind here would only ever be “group” or undefined. Since that matches the semantics of the parent key itself, it’s just easier to use that.
@kerrishotts Thank you for explaining as to why my example was failing.
So if I have understood you correctly, then using parent.kind was the culpret as it was throwing the error because of the “fun JavaScript territory” as you put it.
O and btw, I am ashamed to say I had to look up what “superfluous” meant but it’s a nice word.