3 Replies Latest reply on May 21, 2010 1:26 PM by jimmy_pop

    Find and place CS4 JS

    jimmy_pop

      Hi all,

      I would like the script to run through each line of the file, search the  InDesign file for that number, and if it finds it place the icon I  specify after the text it just found. Here is some pseduo code I've been trying to figure out by piecing together other scripts.

       

      while(input.hasNext())

      {

           var text = input.nextLine();

           if(textExists == true)

       

                app.findTextPreferences.findWhat = text;
                app.changeTextPreferences.changeTo = text + " " + place("C:\\catalog\\icons\\Icon_install.ai") after the text  found;
                myDocument.changeText();

           else

                go to the next line

      }

       

      I would be using a text file that has part numbers in it like

       

      4005

      4003

      5007

      etc

       

      I know a bit of java from school but not much JS. I'm really sorry for being so sloppy, but I'm new to JS. Any help would be appreciated.

        • 1. Re: Find and place CS4 JS
          Harbs. Level 6

          Do you need the same icon each time or a different icon for each?

           

          If it's the same icon, you have two options:

           

          1) You can copy it to the clipboard and use find/change to insert the clipboard contents (like you would in the UI).

           

          2) You can serach the document and use iterate through the finds using

           

          finds[i].insertionPoints[-1].place(myFile)

           

          or (if it's in the clipboard)

          app.select(finds[i].insertionPoints[-1])

          app.paste()

           

          Harbs

          • 2. Re: Find and place CS4 JS
            jimmy_pop Level 1

            Yes I will be using one icon per list of numbers. Are you saying to put all of the part numbers in an array? Also, I don't want to replace the contents of what I find, I just want to add the icon directly after the number it has found.

            • 3. Re: Find and place CS4 JS
              jimmy_pop Level 1
              var finds = new Array("66782","67575");
              
              for(var i = 0; i < finds.length; i++)
              {
                   app.findTextPreferences.findWhat = finds[i];
                   app.select(finds[i].insertionPoints[-1]);
                   app.paste();
              }
              

               

              I just used two part numbers to test this. When I try to run it it gives me an error 21: undefined is not an object on line 6 which is the app.select statement. Any idea?