2 Replies Latest reply on Sep 29, 2008 1:46 AM by (Anil_Yadav)

    CS2: problem while placing the eps according to searched text

      Hi, <br /><br />I'm developing a script which find a tag <math> and place the graphic in place. Everything is going fine with first search and placement but from 2nd selection onwards it is selecting the wrong text (The reason I feel is, the find text length is "6" and placed graphic is "1" so it select the text 5 characters after). And it increase with every search. <br /><br />Or is their any way to use the inDesign's Find Next command. Kindly suggest.<br /><br />Code:<br />     var myDoc = app.activeDocument;<br />     app.findPreferences = app.changePreferences = null; <br />     var anil1=document.search("<math>");<br />     if(anil1.length>=1)<br />     {<br />          myDir = Folder.selectDialog(); <br />          AllGraphics = Folder(myDir).getFiles('*.eps') <br /><br />          for (i=0; i<anil1.length; i++)<br />          {<br />               app.select(anil1[i]);<br />               //myDoc.pages[1].place(AllGraphics[i]);<br />               myDoc.place(AllGraphics[i],false);<br />          }<br />     }
        • 1. Re: CS2: problem while placing the eps according to searched text
          [Jongware] Most Valuable Participant
          This is a well known programming bug -- by the programmer. The length of the text changes on changing the first item you stored in your variable list ("anil1"). Since it is a static list, the change in the text is not carried over into your local variable, and from that point on it really doesn't match the text anymore.

          The common solution to this is to loop over the list items
          i backwards,
          i.e., although the text still changes, it doesn't matter because you already saw it.

          Change your loop to

          >for (i=anil1.length-1; i >=0; i--)

          and you will be fine. And if you're wondering why to use "anil1.length-1" you will have to review your base JS skills.
          • 2. Re: CS2: problem while placing the eps according to searched text
            Level 1
            Thanks for sharing your valuable knowledge with me. Now it working fine. Thanks a lot Jongware.

            Just a quick quick question. While selecting the Find Text, how can I know the page number of selected text. Please suggest.

            Thanks for all your help.

            Thanks,
            Anil Yadav