4 Replies Latest reply on Jun 20, 2012 2:54 AM by Elmer Banate

    Please Help! Inserting index markers base from list of words

    Elmer Banate

      Hi All,

       

      Good day!

       

      I was tasked to create a javascript for inserting index markers to an InDesign document base from list of words. I was able to download as script that will convert colored text to index markers and base on that script, I'm thinking if I could use it to achieved my goal in just changing some of the codes but it didn't work the way I wanted to. I've posted here my codes and hopping someone could help me anyalyze my problem, because production need this script asap.

       

       

      Thanks in advance for any help.

      --elmer

       

       

      main();

      function main(){

        var myObject;

        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

        if(app.documents.length > 0){

        myFindTextByList(app.documents.item(0));

        }

        else{

        alert("No documents are open. Please open a document and try again.");

        }

      }

       

       

      function myFindTextByList(myObject){

        var myFindTextFile = myFindFile("/WordList/FindWordList.txt")

        if(myFindTextFile != null){

        myFindTextFile = File(myFindTextFile);

        var myResult = myFindTextFile.open("r", undefined, undefined);

        if(myResult == true){

        //Loop through the find/change operations.

        do{

        myLine = myFindTextFile.readln();

        //Ignore comment lines and blank lines.

        myFindTextArray = myLine.split("\t");

        myFindText = myFindTextArray[0];

       

        app.findTextPreferences = NothingEnum.nothing;

        app.findTextPreferences.findWhat = myFindText;

       

       

        app.findChangeTextOptions.caseSensitive = false;

        app.findChangeTextOptions.wholeWord = false;

        app.findChangeTextOptions.includeFootnotes = false;

        app.findChangeTextOptions.includeHiddenLayers = false;

        app.findChangeTextOptions.includeLockedLayersForFind = false;

        app.findChangeTextOptions.includeLockedStoriesForFind = false;

        app.findChangeTextOptions.includeMasterPages = false;

       

        // Search the document

        var found_words =  myObject.findText();

       

        // Make index

        var my_index = myObject.indexes.add()

       

       

        // Loop through the paragraphs and create a list of words and mark them as index words

        myCounter = found_words.length-1;

        do {

        var found_word = found_words[myCounter];

        var my_topic_name = found_word.contents;

        var my_topic = my_index.topics.add({name:my_topic_name});

       

        // Create the page reference

        my_topic.pageReferences.add(found_word);

       

        myCounter--;

        } while (myCounter >= 0);

       

       

        } while(myFindTextFile.eof == false);

        myFindTextFile.close();

        }

        }

      }

       

       

      function myFindFile(myFilePath){

        var myScriptFile = myGetScriptPath();

        var myScriptFile = File(myScriptFile);

        var myScriptFolder = myScriptFile.path;

        myFilePath = myScriptFolder + myFilePath;

        if(File(myFilePath).exists == false){

        //Display a dialog.

        myFilePath = File.openDialog("Choose the file containing your word list");

        }

        return myFilePath;

      }

       

       

      function myGetScriptPath(){

        try{

        myFile = app.activeScript;

        }

        catch(myError){

        myFile = myError.fileName;

        }

        return myFile;

      }

      alert("Done indexing!");

        • 1. Re: Please Help! Inserting index markers base from list of words
          [Jongware] Most Valuable Participant

          Elmer Banate wrote:

           

          .. it didn't work the way I wanted to.

           

          It helps if you tell up front what you expected it to do but it doesn't. (For example, this script does not appear to export the freshly generated index as a press- ready PDF. Were you thinking of something like that?)

          • 2. Re: Please Help! Inserting index markers base from list of words
            Elmer Banate Level 1

            Hello Jongware,

             

            First of all thank you for your reply.

             

            What I want to do is, create index markers into InDesign document base on word list that our client gave us. But our problem those words don't have index markers in our InDesign document so woun't able to generate index. What the production is doing, they have to find that word in that document then create index markers for every occurence of the word which very painfull for us because there are thousand of entries need be inserted.

             

            What I trying to do is create as script that could automate in inserting index markers for those words into indesign and after that we could generate index file from that document.

             

            I know there is indexbrutal or indexmatic, but the problem is it will not create inedex markers into InDesign file it will only ouput concordance of text with list of index and each page, our client required us to have those index markers into the InDesign file.

             

            If I'm not mistaken my problem is at this code:

             

            app.findTextPreferences.findWhat = myFindText;

             

            then passing it to a variable name found_words

             

            var found_words =  myObject.findText();

             

            the result became empty, I think there is something wrong within it.

             

             

            Again thank you in advace for you help.

             

            Regards

            --elmer

            • 3. Re: Please Help! Inserting index markers base from list of words
              [Jongware] Most Valuable Participant

              Elmer Banate wrote:

               

              If I'm not mistaken my problem is at this code:

               

              app.findTextPreferences.findWhat = myFindText;

               

              then passing it to a variable name found_words

               

              var found_words =  myObject.findText();

               

              the result became empty, I think there is something wrong within it.

               

              Hmmm hm. Hm. An empty result usually indicates "Not Found", and there are a myriads of possible reasons this would happen. Just for completeness' sake, I'm assuming you are testing with a findWhat phrase of which you know to occur somewhere in your text ...

               

              One possible reason would have been to forget "resetting" the Find What dialog options to its defaults, and for example leave in some formatting options, but I see you got that in your code right before the findText command. Another Usual Suspect would be some weird Find/Change Options that are not applicable, such as Whole Word or Case Sensy. You also got that covered ... so it's down to testing one step at a time.

               

              Can you try the following? Run your script and have it stop right after "found_words" returns an empty result. Do that by inserting the line

               

              if (found_words.length == 0) exit();

               

              after your current findText line. If you open your Find/Change dialog, you will see the exact state, formatting, and text it was looking for with the findText command it just executed. Check every setting. Does it match what you were hoping to see?

              • 4. Re: Please Help! Inserting index markers base from list of words
                Elmer Banate Level 1

                [Jongware] wrote:

                 

                Elmer Banate wrote:

                 

                If I'm not mistaken my problem is at this code:

                 

                app.findTextPreferences.findWhat = myFindText;

                 

                then passing it to a variable name found_words

                 

                var found_words =  myObject.findText();

                 

                the result became empty, I think there is something wrong within it.

                 

                Hmmm hm. Hm. An empty result usually indicates "Not Found", and there are a myriads of possible reasons this would happen. Just for completeness' sake, I'm assuming you are testing with a findWhat phrase of which you know to occur somewhere in your text ...

                 

                One possible reason would have been to forget "resetting" the Find What dialog options to its defaults, and for example leave in some formatting options, but I see you got that in your code right before the findText command. Another Usual Suspect would be some weird Find/Change Options that are not applicable, such as Whole Word or Case Sensy. You also got that covered ... so it's down to testing one step at a time.

                 

                Can you try the following? Run your script and have it stop right after "found_words" returns an empty result. Do that by inserting the line

                 

                if (found_words.length == 0) exit();

                 

                after your current findText line. If you open your Find/Change dialog, you will see the exact state, formatting, and text it was looking for with the findText command it just executed. Check every setting. Does it match what you were hoping to see?

                 

                I can't even past through

                     var found_words =  myObject.findText();

                 

                I got this result error:

                     Error: Object contains no text for find/change.

                 

                whil running the script I've open the Find/Change dialog so I can see what is happening, that Find What field has the value I wanted to see, but when I got the error my Find/Change dialog became emtpy.