4 Replies Latest reply on Aug 23, 2009 8:39 PM by Guy Burns

    Wanted: indexing script to enable editing of Topics

    Guy Burns Level 1

      I started a post in the InDesign forums:

       

      http://forums.adobe.com/message/2120412#2120412

       

      to see if I could overcome a limitation of Indexing, but it appears that the limitation cannot be overcome within InDesign, and judging from a private response by Peter Kahrel, an easy solution may not be possible with scripting either:

       

      The other approach you suggest (selecting a topic and having a script act on that) isn't possible because a script can't see which topic you select in the interface.

       

       

      There may be other ways to implement what I want, so I thought I would try here. This is what I would like to be able to do:

       

      1. I go to Index > Reference and click on the topic I want to modify. It turns blue. Assume I click on Burrows, Bert.

       

      According to Peter, a script cannot access a selection, so this method of selecting a topic is not possible. So, in that case, the script asks me for the Topic I want to modify. It would do so like this in a four-pass loop, or a single dialog box if that is easier to script (my responses are shown bold):

       

      Enter the Topic you want changed (Level 1): Burrows, Bert

      Enter the Topic you want changed (Level 2):

      Enter the Topic you want changed (Level 3):

      Enter the Topic you want changed (Level 4):


      2.  The script then asks me to enter the new Topic levels, again as a four-pass loop (my responses are shown bold):

       

      New Level 1: Burrows

      New Level 2: Bert

      New Level 3:

      New Level 4:

       

      3. The script grabs all the page references from Burrows, Bert and dumps them into the new topic as shown in (2). If the topic I originally selected has sub topics, all those sub topics must remain as sub topics. e.g. if Burrows, Bert has this structure:

       

      Level 1: Burrows, Bert

      Level 2: girlfriends

      Level 3:

      Level 4:

       

      After I run the script, the result should be:

       

      Level 1: Burrows

      Level 2: Bert

      Level 3: girlfriends

      Level 4:

       

       

      Of course, when the index is in final form, I could quite easily manually edit it by inserting paragraph returns (and applying new indented paragraph formats) to achieve the same result as the script -- but I'd have to be certain the index was in final form.

       

      Any comments most appreciated.

       

       

       

       

      Why do I want to do this?

      To illustrate why I want to do the above, I have uploaded the first 2 pages of the draft index (no where near complete as yet) to:

       

      http://www.mediafire.com/download.php?vikoiymzmmn

       

      In there you'll see that the two Akiloff girls have already been sub-topiced (I did that as a test to see what it looks like), and I would like to do the same to Burrows, Byrne and others. As they are now, I could do it without a script because there are very few entries, but when the index is finished, I expect all topics to have more entries than shown.

       

      On the other hand, I do not want the Burns entries (and certain others) sub-topiced. To do so would complicate the look of the index (I think).

        • 1. Re: Wanted: indexing script to enable editing of Topics
          dodtp

          Hi Guy,

           

          we have a lot of experience editing index with InDesign. We are able to export index entries as XML, edit entries and write back entries. By now it is internal use only, but I am confident that we could help you. Please contact me private.

           

          Greetings,

           

          Dirk >> info(at)dodtp.de

          • 2. Re: Wanted: indexing script to enable editing of Topics
            Kasyan Servetsky Level 5

            I remade a little Peter's script, that he posted in InDesign forum, so now it asks for Yes/No confirmation .

             

            #target indesign

             

            if (parseInt (app.version) > 4 && app.documents.length > 0 && app.documents[0].indexes.length > 0) {
                myIndex = app.documents[0].indexes[0];
                myTopics = myIndex.topics.everyItem().getElements();
               
                for (i = myTopics.length-1; i > -1; i--) {
                    temp = myTopics[i].name.match (/^([A-Z][-a-z]+), ([A-Z][-a-z]+)$/);
                    if (temp != null) {
                        for (j = myTopics[i].pageReferences.length-1; j > -1; j--) {
                            if (confirm(temp[1] + ", " + temp[2])) {
                                new_topic = myIndex.topics.add (temp[1]).topics.add (temp[2]);
                                new_topic.pageReferences.add (myTopics[i].pageReferences[j].sourceText, PageReferenceType.currentPage);
                                myTopics[i].name += "@@@@"
                            }
                        }
                     }
                  }
             
                myTopics = myIndex.topics.everyItem().getElements();
                for (i = myTopics.length-1; i > -1; i--)
                  if (myTopics[i].name.search ("@@@@") > -1)
                     myTopics[i].remove ();
            }

            • 3. Re: Wanted: indexing script to enable editing of Topics
              Peter Kahrel Adobe Community Professional & MVP

              Thanks Kasyan, good idea. Another defect was that the new topic was created at the wrong place: it was created many times (for each page reference of the original topic). It doesn't break the script, but mslows it down probably. The two if-statements can be combined as well, so the correct version would be something like this:

               

              for (i = myTopics.length-1; i > -1; i--)
                 {
                 temp = myTopics[i].name.match (/^([A-Z][-a-z]+), ([A-Z][-a-z]+)$/);
                 if (temp != null && confirm(temp[1] + ", " + temp[2]))
                    {
                    new_topic = myIndex.topics.add (temp[1]).topics.add (temp[2]);
                    for (j = myTopics[i].pageReferences.length-1; j > -1; j--)
                       {
                       new_topic.pageReferences.add (myTopics[i].pageReferences[j].sourceText, PageReferenceType.currentPage);
                       myTopics[i].name += "@@@@"
                       }
                    }
                 }

               

              This business with adding @@@@ and deleting those topics en masse afterwards can be done more elegantly, but it works like this.

               

              Peter

              • 4. Re: Wanted: indexing script to enable editing of Topics
                Guy Burns Level 1

                Peter has written three scripts which overcome the problems alluded to above. I have started a new thread to alert users to the scripts:

                 

                http://forums.adobe.com/message/2199027#2199027