How to find benchmarks

Hello

I'm trying to run 'index' for my simple Indesign to html conversion tool and I'm totally confused on how to do it and with the management of this "index" extendscript So here's (a lot of) questions about this:

  1. When I'm traveling all characters in a paragraph, how can I identify 'benchmarks '? RegExp, specialCharacter...? * Answer me * working with Grep search for "\~I."
  2. After found a 'mark of index' how can we if find the associated "topic"?
  3. If it can be that a single "index" in a document, why is there a property "index"?
  4. What is a 'indexSection?

Hope that there will be someone to free my mind

Thank you very much

Sebastian,

If the writers are not stubborn that they will never get their script problems solved! A note on terminology: ExtendScript, incidentally is just JavaScript. What you mean is the InDesign object model.

It is true that when you select an index mark in text, and you have the Index opened Panel, the referenced topic is highlighted in the Panel. But that is not exposed to scripts, i.e. the character object is not a property "subject to". However, you can determine the subject of the selected marker, even if it's a pretty laborious method. Index markers are characters of the text, so that they have a history of parent and an index. pageReferences have a sourceText property, which is an insertion point. To find the subject of an index mark, you must compare the insertion point of the marker with the insertion of the pageReferences points.

The feature that miss you - by selecting an index mark so that its parent theme is selected in the Index panel - can be scripted as follows:

$.writeln (findTopic (app.selection[0]).name);

function findTopic (marker) {
    var topics = app.documents[0].indexes[0].allTopics;
    var mStory = marker.parentStory;
    var mIndex = marker.insertionPoints[0].index;
    var pRefs;
    for (var i = topics.length-1; i >= 0; i--) {
        pRefs = topics[i].pageReferences.everyItem().getElements();
        for (var j = pRefs.length-1; j >= 0; j--){
            if (pRefs[j].sourceText.parentStory == mStory && pRefs[j].sourceText.index == mIndex) {
                return pRefs[j].parent;
            }
        }
    }
    return "";
}

Select an index mark in a text and run the script (it does not select anything in the Panel, of course). Now, if you have several index markers, then looping through them to find their topic names could in principle be made as follows:

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '~I';
markers = app.documents[0].findGrep();
for (var i = markers.length-1; i >= 0; i--) {
    $.writeln (findTopic (markers[i]).name);
}

But it would be horribly inefficient (very specific). Better to first to build a table of choice of the pageReferences and their sourceText index history IDs so that you can quickly find topic names.

Your particular approach - to loop through all the characters - needs a bit of a change in what you have to compare each character at index.

Something like this:

for (var i = 0; i < myChars.length; i++) {
   if (myChars[i].contents == '\uFEFF') {  // myChar is probably an index marker
      var topic = (findTopic (myChars[i]).name);
      if (topic != "") {
          $.writeln (topic);
      }
   }
}

Peter

Tags: InDesign

Similar Questions

Maybe you are looking for