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

Index markers out of place after tables with more than 6 rows..

New Here ,
May 23, 2025 May 23, 2025

Hello,

I am importing large XML files and creating books. I can create the books fine and index markers.. but when I have tables that seem to be larger than 6 rows, the markers start to show up in random places. 

I include a very small sample XML and my script and yuo can see even 1 page document the markers start to become random. If no tables, then no issues, but the tables are throwing. 

can anyone share any idea whats happening. I have tried a variety of approaches and still cant' solve it. 

 

I would really really appreciate any insight.

 

I attach example xml, my index script and screen shot..

the code is just simply adding a a reference to the marker parent"

var markerText = indexMarker.xmlAttributes.itemByName("text").value;
var targetParagraph = indexMarker.parent;
var insertionPoint = targetParagraph.insertionPoints[0];
 
currentTopic.pageReferences.add(insertionPoint);
TOPICS
How to , Scripting , SDK
269
Translate
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

correct answers 1 Correct answer

Community Expert , May 24, 2025 May 24, 2025

The workaround that Roland mentioned works quite well, I've used it for many years. See th code sample, below.

 

Two comments on your code, Ray:

(1) In your code, variables are created in each iteration of the for-loop. It's more efficient to declare them before the for-loop.

(2) It's not necessary to check whether a topic exists: just create it. If it exists InDesign ignores it.

 

And please go to the UserVoice link that Roland posted and vote for the bug. I've given up hope that it'll ever be

...
Translate
Community Expert ,
May 23, 2025 May 23, 2025

Try wrap the markers in their own paragraphs

 

<paragraph aid:pstyle="markerParagraph">
  <marker text="AfterTable"/>
</paragraph>
<paragraph aid:pstyle="paragraph1">
  <bullet>(b)</bullet>
  <leadingText>This subpart defines...</leadingText>
</paragraph>

 

Translate
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
Contributor ,
May 24, 2025 May 24, 2025

Hi Ray,

 

this is a known bug when tables are present in the document.

 

You can calculate the offset and then move the index marker. However, this can be quite tricky with a complex document structure. Or create the index marker in a separate text frame first and then move it to the desired position.

 

Roland

Translate
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 ,
May 24, 2025 May 24, 2025

The workaround that Roland mentioned works quite well, I've used it for many years. See th code sample, below.

 

Two comments on your code, Ray:

(1) In your code, variables are created in each iteration of the for-loop. It's more efficient to declare them before the for-loop.

(2) It's not necessary to check whether a topic exists: just create it. If it exists InDesign ignores it.

 

And please go to the UserVoice link that Roland posted and vote for the bug. I've given up hope that it'll ever be fixed but you never know.

 

try {
  // Define your variables outside the for-loop
  markerText = indexMarker.xmlAttributes.itemByName("text").value;
  targetParagraph = indexMarker.parent;
  insertionPoint = targetParagraph.insertionPoints[0];
  levels = markerText.split(":");
  
  // Create main topic
  newTopic = myIndex.topics.itemByName(levels[0]);

  // Create subtopics
  for (i = 1; i < levels.length; i++) {
    newTopic = newTopic.topics.add(levels[i]);
  }

  pageRef = newTopic.pageReferences.add (insertionPoint);

  // If the index of the pageReference's insertion point
  // is not immediately after 'insertionPoint's insertion point,
  // then move the pageReference (sourceText is an InsertionPoint object)

  if (Math.abs (pageRef.sourceText.index - insertionPoint.index) > 0) {
    try {
      pageRef.sourceText.parentStory.characters[pageRef.sourceText.index].move (
        LocationOptions.AFTER, 
        insertionPoint
      );
    } catch (_) {
      // . . .
    }
  }
} catch ...
  ...
}

Translate
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 ,
May 24, 2025 May 24, 2025
LATEST

That is fantastic.. 2 days I spent on this.. I was not aware the page reference addition would return an object we could inspect for the location.. very helpful! Thank you @Peter Kahrel @Roland Dreger @Eugene Tyson 

Translate
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