Skip to main content
Participating Frequently
January 2, 2009
Question

[JS] :: [CSX] - PageItem Stacking Order

  • January 2, 2009
  • 16 replies
  • 11021 views
Hi folks,

Does any one here have any knowledge and or experience on how indesign handles the stacking order of page items.

I have a simple script which can be viewed here:
http://home.exetel.com.au/thunder/img/simpleScript.js

The indesign file I am opening can be downloaded here:
http://home.exetel.com.au/thunder/img/sample%20Folder.zip

I am trying to use the index property of pageItem to determine the proper stacking order--I am trying to sort the page Items from top down.

In This example inDesign reports that the object 'little circle' is underneath 'big Circle' and the index numbers in general do not seem to match how I have placed the objects on top of each other in the document.

Is this the correct way to determine stacking order?
This topic has been closed for replies.

16 replies

Known Participant
January 4, 2009
in VBS - after grouping selected items - order is from top to bottom
so - I think there is no need to play with duplicates ... just group, read order of elements in group and ungroup
of course - this is OK ONLY for items from same layer
in case of few layers - this need to be done for each layer

robin

--
www.adobescripts.com
Peter Kahrel
Community Expert
Community Expert
January 4, 2009
>I think all new temp groups should be labeled and only these groups should be ungrouped

Good point. The line that creates the groups should then be
>doc.pages.groups.add ([dupl, p_items], {label: 'dupl_group'});

and the line that ungroups should then be
>doc.groups.item('dupl_group').ungroup();

Peter
Peter Kahrel
Community Expert
Community Expert
January 4, 2009
Ben,

What a great idea: duplicate pageItems and group the original and the duplicate so that all page items are of the same type. But you're making things very complicated. Your brilliant idea can be scripted simply as follows: on each page, duplicate each page item and group it with its original. Label the duplicates so that you can delete them easily later on:
doc = app.activeDocument;

for (i = 0; i < doc.pages.length; i++)
{
p_items = doc.pages.allPageItems;
for (j = 0; j < p_items.length; j++)
{
dupl = p_items.duplicate();
dupl.label = 'duplicate';
doc.pages.groups.add ([dupl, p_items]);
}
}

Afterwards these two lines ungroup everything and delete the duplicates:
doc.groups.everyItem().ungroup();

doc.pageItems.item ('duplicate').remove()


Peter
Known Participant
January 4, 2009
Peter,

unless you don't have other groups you don't want to ungroup ;)
I think all new temp groups should be labeled and only these groups should be ungrouped

robin

--
www.adobescripts.com
_Ben_J_D_Author
Participating Frequently
January 4, 2009
I had another go with my grouping strategy and came up with a solution that works. I have uploaded a new modified version of my script here:
http://home.exetel.com.au/thunder/img/simpleScript2.js

Basically I create a bunch of empty text frames and group them to all of the individual page items, this creates a new set of page items who are all of the same type 'Group' and therefore share unique indicies which represent their stacking order.

This script could surely by improved and optimized. This method seems entirely over the top for something that should be very simple. I am open to better suggestions.
_Ben_J_D_Author
Participating Frequently
January 4, 2009
Thank you for your reply Peter,

Your message helped me understand how indesign assigns indicies to PageItems and why I cant use them to determine a stacking order. (Unless they are all the same type of object). Can you think of any other ways this might be done or any scripts out there that are already doing this? I thought if I could add all of my page items to groups and therefore bring them all into the same type this would produce an accurate stacking order. But the groups I make do not stay in the same order and find myself back to square one.

Thanks again for your reply.
Ben
Peter Kahrel
Community Expert
Community Expert
January 2, 2009
Indexes indicate the stacking order of objects, but only of objects of the same type. You have two types of object on your page, three Ovals and two Rectangles. The Ovals have indexes 0, 1, and 2, the Rectangles, 0 and 1. On pages with objects of mixed types it is therefore not possible (or not straightforward anyway) to determine those objects' stacking order. (An object's id doesn't change when you send it to the front or back, so that doesn't tell you anything about stacking order.)

Peter