2 Replies Latest reply on Apr 2, 2013 7:32 PM by poopwowwo

    want to output the text of an index marker at the same position of the index marker

    poopwowwo

      Hello.

       

      I want to output the text of index markers at the same position of the index markers, using InDesign JavaScript.

       

      There are two ways are in my mind now.

      1. Use Indexes Objects, looping through them.

           In this way, you can get the contents text of Index markers, but you cannot get the position which you can use to insert the text.

           Am I right?

      2. Use .findText method with searching text "^I".

           In this way, you can get the position, but you cannot cast the found character to Index Object, so you cannot get the Index text.

           Am I right?

       

      Is there any way to solve either one of those problems, or both?

       

      Thanks to your kindness.

        • 1. Re: want to output the text of an index marker at the same position of the index marker
          [Jongware] Most Valuable Participant

          poopwowwo wrote:

           

          1. Use Indexes Objects, looping through them.

               In this way, you can get the contents text of Index markers, but you cannot get the position which you can use to insert the text.

               Am I right?

           

          No. An Index object consists of Topics, and every single Topic (one entry in the index) can point to one or more Page References -- the actual 'page numbers'. A Page Reference, in turn, points to "text", and that's the position of this particular combination of index entry-and-position.

          See http://jongware.mit.edu/idcs6js/pc_PageReference.html for the proper hierarchy.

           

          indexTopics = app.activeDocument.indexes[0].topics;
          for (i=indexTopics.length-1; i>=0; i--)
          {
           for (j=indexTopics[i].pageReferences.length-1; j>=0; j--)
            indexTopics[i].pageReferences[j].sourceText.insertionPoints[0].contents = '('+indexTopics[i].name+')';
          }
          

          2. Use .findText method with searching text "^I".

               In this way, you can get the position, but you cannot cast the found character to Index Object, so you cannot get the Index text.

               Am I right?

           

          No -- but it's more difficult to get something useful out of this. In this case, you would need to compare the index of the 'character' "^I" against every single text position of type PageReference of every single Topic.

          • 2. Re: want to output the text of an index marker at the same position of the index marker
            poopwowwo Level 1

            Jongware-san,

             

            You have kindly helped me so much. Thank you so much. I appreciate it.

             

            By the way,

            Your sample code did not work at first.

            After replacing ".topics" with ".allTopics", it did work. (version problem? Mine is CS6. anyway, it does not matter)

             

            I'm a beginner of InDesign JS, not knowing much about InDesign Object Model;

            but I was in a hurry, so I had to ask your help this time.

            Next time I'll study it harder before asking.

            Thanks, again.