Layers have a property called itemIndex which you can get via batchPlay.
However, this property is a bit error-prone as the true index is affected by whether the document has a background layer or not.
Essentially, the layer’s index is:
itemIndex ← if there’s no background layer
itemIndex - 1 ← if there’s a background layer
The document descriptor has the property hasBackgroundLayer which you can use for that.
layerSectionStart and layerSectionEnd ist not anytihng you need to worry about when creating a group. What you see in the descriptor is what the operation returned, but I’m pretty sure that those properties get ignored anyways when you call it like that. To group layers programmatically, you only need to have them selected. Then they’re referenced by the following part:
You’re getting the whole layer descriptor, which is way less performant than only getting the single property you need. In order to do so, you can add { _property: *propertyName* } to the _target array. In this case { _property: "itemIndex" }
Specifying the target document in the _target array doesn’t do anything bad, but you can also leave it away since it’s the default.
Don’t forget the background-fix I’ve explained before, otherwise the code might run into problems with specific documents.
With regards to your first note about the whole layer descriptor, even with _property in the _target array, the code above still returns the whole layer. Is this the correct behavior? I expected to just get the itemIndex as the result.
Has something changed with this? I am just testing this for the first time. The layer’s index in my testing seems to always be itemIndex - 1 whether there is a background layer or not.