Skip to main content
Participant
May 24, 2025
해결됨

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

  • May 24, 2025
  • 3 답변들
  • 694 조회

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);
최고의 답변: Peter Kahrel

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 ...
  ...
}

3 답변

Peter Kahrel
Community Expert
Community Expert
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 ...
  ...
}

Participant
May 24, 2025

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 

Inspiring
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

Community Expert
May 24, 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>