Copy link to clipboard
Copied
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"
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
...Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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 ...
...
}
e
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now