9 Replies Latest reply on Oct 22, 2008 7:01 AM by (Robert_Dunn)

    IndexFromList with one subtopic

      I'm using Martin Fischer's Index from list with one subtopic script, which works wonderfully well. However, when a topic in my list contains a double quotation mark for the inch marker, as in a 2" Bolt, that topic is passed by. Can someone suggest a change to Martin's script that would handle this?

      Thanks,

      Robert Dunn
        • 1. Re: IndexFromList with one subtopic
          Martin Fischer Level 2
          Hallo,

          the error is caused by this function:
          function makeEntry(oneWord) { 
          
          app.findTextPreferences.findWhat = oneWord;
          var myResult = myDoc.findText(); 
          for (var oneEntry = myResult.length-1; oneEntry >=0; oneEntry--) { 
            // Fehler abfangen, z.B. Fußnoten ausnehmen
            try {
             // Hinzufügen des Themas
             myDoc.indexes[0].topics.add(oneWord); 
             // Hinzufügen der Referenz
             myDoc.indexes[0].topics.item(myResult[oneEntry].contents).pageReferences.add(myResult[oneEntry],   PageReferenceType.currentPage); 
            }
            catch(e) {}
          }
          }

          Especially by the command that should add the page reference:

          myDoc.indexes[0].topics.item(myResult[oneEntry].contents).pageReferences.add(myResult[oneEntry],   PageReferenceType.currentPage); 

          I couldn't solve the problem yet.
          The original script can be found at http://www.hilfdirselbst.ch/gforum/gforum.cgi?post=322824#322824

          Martin Fischer
          • 2. Re: IndexFromList with one subtopic
            Martin Fischer Level 2
            Robert,

            you may temporary change the string for the name of the topic, add the topic, add the page reference and then rename the topic:
            change name: oneWord.replace( /"/g, '##1##' )
            rename: aTopic.name = aTopic.name.replace ( /##1##/g, '" ')

               // Hinzufügen des Themas
               var aTopic = myDoc.indexes[0].topics.add(oneWord.replace( /"/g, '##1##' ) ); 
               // Hinzufügen der Referenz
               aTopic.pageReferences.add(myResult[oneEntry],   PageReferenceType.currentPage); 
               aTopic.name = aTopic.name.replace ( /##1##/g, '"' );


            I feel certain, somebody will find a better solution.
            But this works for me.

            Martin
            • 3. Re: IndexFromList with one subtopic
              Level 1
              Thanks, Martin:
              I think your changes apply to the single topic version of your script. I have been able to make them work partially in the with_one_subtopic version when there is only one topic, but am having some trouble when there is an entry with a subtopic. Any suggestions?

              Thanks again for your help.

              Robert
              • 4. Re: IndexFromList with one subtopic
                Martin Fischer Level 2
                Hi Robert,

                > but am having some trouble when there is an entry with a subtopic

                You had better told before which version you use.
                Or tellthe source link.
                For there are different versions of this script for different versions of InDesign and of different functionality.

                Still stumbling in the dark this might be what you have been looking for:

                function proceedEntry( oneEntry ) {
                    var doubleQuote = new Array;
                    app.findTextPreferences.findWhat = oneEntry[ oneEntry.length-1];   
                    var myResult = myDoc.findText();  
                    var myTopic = myDoc.indexes[0];
                    for (var t = 0; t < oneEntry.length; t++ )  {
                        if ( oneEntry[t].match ('"' ) )
                        {
                            // temporary change the name with double quotes before adding the topic
                            myTopic = myTopic.topics.add(oneEntry[t].replace( /"/g, '##1##' ) );  
                            doubleQuote.push( myTopic );
                        }
                        else
                            myTopic = myTopic.topics.add(oneEntry[t] );  
                    }
                    for (var i = myResult.length-1; i >=0; i--)
                        myTopic.pageReferences.add(myResult[i],  PageReferenceType.currentPage);
                    // rename the topic with the substituted string for double quotes
                    for ( var d = 0; d < doubleQuote.length; d++ )
                        doubleQuote[d].name = doubleQuote[d].name.replace ( /##1##/g, '"' );  
                }

                The workaround is still the same:
                Temporary change the double quotes to another string, before making the topics, catch the changings, rename the changed topic names afterwards.

                Martin
                • 5. Re: IndexFromList with one subtopic
                  Level 1
                  Hi Martin:
                  Thanks again for your time. I didn't realize that there were different versions of your program, and I apologize for leaving you "in the dark." I took the one off of the Adobe site, which was posted about a year ago. As I said, it works beautifully, with this one exception. I have appended it to this message (which I now realize I should have done at first) in case you have time to look at it.

                  Thanks again,

                  Robert

                  //-------------------------------------------------------------------------
                  // 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;
                  }
                  //-------------------------------------------------------------------------
                  • 6. Re: IndexFromList with one subtopic
                    Level 1
                    I'm sorry for that unformatted mess in my previous post. It looked good when I sent it. I tried again, but with the same result.

                    Robert
                    • 7. Re: IndexFromList with one subtopic
                      Level 1
                      Sorry, can't get it to send formatted.

                      R
                      • 8. Re: IndexFromList with one subtopic
                        Martin Fischer Level 2
                        Robert,

                        It's ok.

                        Please give me some time.
                        For I do have less, at the moment.

                        Martin
                        • 9. Re: IndexFromList with one subtopic
                          Level 1
                          Please give me some time.
                          For I do have less, at the moment.

                          Of course, take your time. I appreciate everything you have done.
                          Thanks again for your help.

                          Robert