How can I move some layers into a group layer

I assume that’s why you asked about getting the index by name? (Answer here)

Moving the layer to the index is the correct way. If you want the layer to be at the top of the group it’s rather easy: You just move it to the groups index - 1.
However, moving it to the bottom will become a lot more complex. Groups in Photoshop are a bit like HTML-tags, they have a start and an end, with the content in between.

In order to get the index of the group end, you’d have to iterate all layers (starting at the group index) to find the ending. However, groups can also contain other groups, so you need some kind of counter that you increase and decrease for every group start or end. Once the counter is 0 and you find a group end, that’s the end of your original group.

1 Like