2 Replies Latest reply on Apr 1, 2008 1:24 AM by (gaphic)

    CS3 IndexFromList.jsx  with a twist

    Level 1
      I'd like to thank Martin Fischer for rewriting the IndexFromList.jsx script for CS3: http://www.hilfdirselbst.ch/foren/Skript_zum_Index_generieren_P322824.html#322824

      It takes a list of index entries and indexes every occurence of the topics in the list. Usually the authors of the books I typeset have created such a topic list, so the script really speeds up the proces of finding the page references.

      The list drawn up by the authors needs tweaking, as they don't take into account the way Indesign's indexing deals with case, whole word and proper names.

      This is an example of what a portion of the concordance list could look like before and after tweaking:

      postmodernism
      -------------
      postmodern
      postmodernism
      postmodernist
      postmodernists
      postmodernity

      In the final index these topics are grouped into the 'postmodernism' entry. But that leaves a lot of manual work changing the index topics of the similar terms. An added step to the script could perform this automatically, if you change the concordance list into a two column list. The right column indicates which terms should be grouped:

      postmodern | postmodernism
      postmodernism | postmodernism
      postmodernist | postmodernism
      postmodernists | postmodernism
      postmodernity | postmodernism

      So instead of adding (oneWord) the script would add the term in the second column:

      // Hinzufügen des Themas
      myDoc.indexes[0].topics.add(oneWord);

      Or is this too complicated a way to address the problem?
        • 1. Re: CS3 IndexFromList.jsx  with a twist
          Martin Fischer Level 2
          Hi Gaphic,

          here's a new version of the script: http://www.hilfdirselbst.ch/gforum/gforum.cgi?post=343938#343938


          //-------------------------------------------------------------------------
          // IndexFromList_withOneSubtopic_CS3.jsx  
          //DESCRIPTION: Erzeugt Indexeinträge anhand einer externen Konkordanzdatei, die über einen Dialog ausgewählt wird. 
           
          var myDoc = app.activeDocument;  
          var myList = File.openDialog ("Liste mit Indexbegriffen"); 
          if (!myList) exit(); 

          clearFindChangeSettings();
          app.findChangeTextOptions.wholeWord = true;
          app.findChangeTextOptions.caseSensitive = true;
          app.findChangeTextOptions.includeFootnotes = true;

          var myEntries = getWords(myList); 
          proceedWithList(myEntries); 
          alert("Erledigt!"); 
           
          // Konkordanzliste einlesen 
          function getWords (aFile) { 
          if (aFile.exists) { 
            aFile.open ('r', undefined, undefined); 
            var aText = aFile.read()+'\n'; 
            // löschen von Leerzeichen am Ende der Zeile + löschen von leeren Zeilen  
            aText = aText.replace(/ +\n/g, '\n').replace(/\n+/g, '\n');  
            // ersetzen von mehrfach aufeinander folgende Leerzeichen aller Art durch ein Leerzeichen 
            aText = aText.replace(/ {2,}/g, ' '); 
           
            var words = aText.split('\n');
            var myPairs = getPairs( words );
            aFile.close(); 
            return myPairs; 

          else { 
            exit(); 



          function getPairs( w )
          {
          var thePairs = new Array;
          for (i = 0; i < w.length; i++ )
            thePairs.push( w[i].split(' | ') );
          return thePairs;
          }
           
          // Begriffsliste abarbeiten 
          function proceedWithList (w) { 
          // bei Bedarf wird ein neuer Index erzeugt 
          if (myDoc.indexes.length == 0)  
            myDoc.indexes.add();  
            
          for (var i = 0; i < w.length; i++)  
            if (w[i] != "")  
             makeEntry(w[i]); 
           
          // Aktualisieurng des Index 
          myDoc.indexes[0].update(); 
          }  
           
          // Indexeintrag erzeugen 
          function makeEntry(oneEntry) {
          if ( oneEntry.length == 1 )
            app.findTextPreferences.findWhat = oneEntry[0];
          else
            app.findTextPreferences.findWhat = oneEntry[1];

          var myResult = myDoc.findText();  
          for (var i = myResult.length-1; i >=0; i--) {  
            // Fehler abfangen, z.B. Fußnoten ausnehmen 
            try { 
             // Hinzufügen des Themas 
             myDoc.indexes[0].topics.add(oneEntry[0]);  
             // Hinzufügen der Referenz 
             if ( oneEntry.length == 1 )
              myDoc.indexes[0].topics.item(myResult[i].contents).pageReferences.add(myResult[i], PageReferenceType.currentPage);  
             else
             {
              //myDoc.indexes[0].topics.add( oneEntry[0]);
              myDoc.indexes[0].topics.item( oneEntry[0] ).topics.add( oneEntry[1]);
              myDoc.indexes[0].topics.item( oneEntry[0] ).topics.item( myResult[i].contents ).pageReferences.add(myResult[i], PageReferenceType.currentPage);  
             }
            } 
            catch(e) {} 



          //Clear any existing find/change settings.
          function clearFindChangeSettings()
          {
          app.findTextPreferences = NothingEnum.nothing;
          app.changeTextPreferences = NothingEnum.nothing;
          }
          //-------------------------------------------------------------------------


          This version supports one topic and one topic with one subtopic.
          The list should look like this:

          topic 1
          topic 2 | subtopic 1
          topic 2 | subtopic 2
          topic 2 | subtopic 3
          ...


          You can manage multiple indexes (names, places, subjects) like this:

          names | Kafka
          names | Peirce
          names | Williams
          places | Berlin
          places | Munich
          subjects | health
          subjects | sunshine
          ..

          Maybe some day there will be a version which manages more than one subtopic.

          regards
          Martin Fischer
          • 2. Re: CS3 IndexFromList.jsx  with a twist
            Level 1
            Martin, thanks for posting the new version of your script. The ability to include a level of subtopics is great.

            And it's fast as well - just tested it on a 400 page book.