• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

I'm trying to create an array of indexes for where the rectangles (images) in my document are embedded.

New Here ,
Apr 05, 2019 Apr 05, 2019

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! 

TOPICS
Scripting

Views

394

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

Hi, try this; myArray = app.activeDocument.stories.everyItem().rectangles.index;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 05, 2019 Apr 05, 2019

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2019 Apr 07, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 08, 2019 Apr 08, 2019

Copy link to clipboard

Copied

LATEST

Thank you.  That makes sense!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines