Copy link to clipboard
Copied
I'm not sure why this line isn't working:
myArray = app.activeDocument.rectangles.everyItem( ).index;
Maybe I just don't fully understand how everyItem() works.
I've also tried this:
myArray = app.activeDocument.rectangles.parent.everyItem( ).index;
It's my understanding that there is a character at the insertion point of the image that is the parent of the rectangle object, but maybe I'm off here?
Please help!
Copy link to clipboard
Copied
Hi, try this; myArray = app.activeDocument.stories.everyItem().rectangles.index;
Copy link to clipboard
Copied
It's not working
I have a test document with 1 page, a full text frame on that page. The text frame contains 4 short paragraphs with 1 image anchored at the end of the first paragraph and second image anchored at the end of the 4th paragraph. When I run the line of code:
myArray = app.activeDocument.stories.everyItem().rectangles.everyItem().index
I get a 2-element array, but the it is just [0,0]. My isn't it giving the actual indexes for the images?
Copy link to clipboard
Copied
It's not a problem of any of the script approaches, it's the way InDesign sees/reports page items and other objects. You can see that when you select one of your rectangles and do app.selection[0].index -- it returns 0. Take another embedded rectangle, and its index, too, is 0.
It does make sense, though. Indexes indicate the rank of similar objects in a parent domain. When you place two non-embedded rectangles on a document page, they have the same parent (the page), and app.documents[0].rectangles.everyItem().index returns [0,1]. When you move one of the rectangles to another page, the rectangles have different parents and app.documents[0].rectangles.everyItem().index returns [0,0].
It's the same with your embedded rectangles: they're in the same story, but they have different parents (different characters) so that each rectangle is the only rectangle in its domain, and therefore each has index 0.
Peter
Copy link to clipboard
Copied
Thank you. That makes sense!