Arranging Page Items
Page items in an InDesign layout can be arranged in front of or behind each other by adjusting their stacking order within a layer, or can be placed on different layers. The following script fragment shows how to bring objects to the front or back of their layer, and how to control the stacking order of objects relative to each other.
//Given a rectangle "myRectangle" and an oval "myOval",
//where "myOval" is in front of "myRectangle", bring
//the rectangle to the front...
When you create a page item, you can specify its layer, but you can also move a page item from one layer
to another. The item layeritemLayerItemLayer property of the page item is the key to doing this, as shown
in the following script fragment (for the complete script, refer to ItemLayer).
//Given a rectangle "myRectangle" and a layer "myLayer",
//send the rectangle to the layer...
myRectangle.itemLayer = app.Documents.item(0).layers.item("myLayer");
The stacking order of layers in a document can also be changed using the move move method of the layer
itself, as shown in the following script fragment (for the complete script, refer to MoveLayer).
//Given a layer "myLayer", move the layer behind
//the default layer (the lowest layer in the document
Thanks but that's not quite what I mean.
When you look at a layer in the layers panel, it contains, let's say, 5 groups. Those groups are assigned an index from 1 to 5 with 1 being the group at the top of the list and 5 being the one at the bottom. I want to be able to take the group at the bottom of the list and move it to the top. It's like you have described with changing the layer order but with groups wtihin a layer instead. The Move function just allows moving a group to another location on the page, not changing its order in the list.
For that purpose you can use following;
As AnshunJain19 wrote:
brings myRectangle to the top of the layer if no parameter specified.
brings myRectangle in front of myOval
If they are not on the same layer ==> use move method to equal layers first and bringToFront() - or sendToBack() - to set order.