2 Replies Latest reply on Oct 13, 2016 12:59 PM by Peter Kahrel

    find page number of a grep search

    jakec88782761 Level 2

      I've got a script which finds a GREP expression.


      I want to print the found text into an InDesign document with the corresponding page number.


      At the moment my script works fine when it's only printing the contents of the found text.


      However when I add this line:


      for (var i = 0; i < found.length; i++) {


              var foundReport = found[i]; // found is the variable which stores the findGrep() method.


              var page = foundReport.contents.parentTextFrames[0].parentPage;


              tFrame.contents += foundReport.contents+ "on page "+ page.name+'\r';    //tFrame is the variable which stores the added documents text frame.




      The script just creates an empty text frame with no text.


      Am I using the DOM wrong?



        • 1. Re: find page number of a grep search
          Loic.Aigon Adobe Community Professional

          Don't you have any errors ?


          If the text is hosted in a frame located on the pasteboard, parentPage will return null. Then you can have an error at page.name that would make teh script fails.


          If you catch silently this error, you won't notice any changes.





          • 2. Re: find page number of a grep search
            Peter Kahrel Adobe Community Professional & MVP

            Instead of


            var page = foundReport.contents.parentTextFrames[0].parentPage




            var page = foundReport.parentTextFrames[0].parentPage


            foundReport.contents is plain text, which (in InDesign's DOM) doesn't have a parent, let alone a parentTextFrame.


            Naturally, everything that Loic mentioned about stuff being on the pasteboard (i.e. not really on apage) applies too.