11 Replies Latest reply on Jan 15, 2014 9:27 AM by bradsdb

    Page number of replaced text

    bradsdb

      I am using a customized version of the FindChangeByList Script included with inDesign. What it currently does is output to a log file with all the changes made in the document and the total of changes made.

       

      I would like to add a page number to each of the changed items but so far have not been able to find a way that actually shows that page number. Is this possible?

       

      Thanks in advance,

       

      Brad

        • 1. Re: Page number of replaced text
          Peter Kahrel Adobe Community Professional & MVP

          myFoundThing.parentTextFrames[0].parentPage.name

           

          That's for CS5 and later. Earlier versions are a little harder.

           

          Peter

          • 2. Re: Page number of replaced text
            bradsdb Level 1

            Thanks for the reply Peter - I have tried this iteration before however I feel I may not be using the correct variable for "myFoundThing" and the several options I have tried all give me an error 21 "undefined is not an object",

             

            Here is the current function that runs:

             

            function myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){

                      //Reset the find/change preferences before each search.

                      app.changeTextPreferences = NothingEnum.nothing;

                      app.findTextPreferences = NothingEnum.nothing;

                      var myString = "app.findTextPreferences.properties = "+ myFindPreferences + ";";

                      myString += "app.changeTextPreferences.properties = " + myChangePreferences + ";";

                      myString += "app.findChangeTextOptions.properties = " + myFindChangeOptions + ";";

                      app.doScript(myString, ScriptLanguage.javascript);

                      myFoundItems = myObject.changeText();

                      if(myFoundItems != "") {

                                myChangeCount++;

                                var pageNum = myFindPreferences.parentTextFrames[0].parentPage.name;

                                var chopFrontFind = myFindPreferences.replace('{findWhat:"', '');

                                var chopEndFind = chopFrontFind.substring(0, chopFrontFind.length - 2);

                                var chopFrontChange = myChangePreferences.replace('{changeTo:"', '');

                                var chopEndChange = chopFrontChange.substring(0, chopFrontChange.length - 2);

                                logInfo = logInfo + "\n" + chopEndFind + " changed to -> " + chopEndChange + " on page " + pageNum;

                      }

                      //Reset the find/change preferences after each search.

                      app.changeTextPreferences = NothingEnum.nothing;

                      app.findTextPreferences = NothingEnum.nothing;

            }

            • 3. Re: Page number of replaced text
              Peter Kahrel Adobe Community Professional & MVP

              I don't understand why you do the replacement the way you do, but that may be because of some constraints that the FindChangeByList script imposes on you. The problem is in this line:

               

              var pageNum = myFindPreferences.parentTextFrames[0].parentPage.name;
              

               

              findPreferences don't have parentTextFrames. You need to use myFoundItems and collect the page numbers of each individual found item, something like this:

               

              var pageNumbers = [];
              for (var i = 0; i < myFoundItems.length; i++) {
                 pageNumbers.push (myFoundItems[i].parentTextFrames[0].parentPage.name);
              }
              

               

              then later:

               

              logInfo = logInfo + "\n" + chopEndFind + " changed to -> " + chopEndChange + " on pages " + pageNumbers.join(',');
              

               

              By the way, you can remove those four 'chop' lines and change the loginfo line as follows:

              logInfo = logInfo + "\n" + app.findTextPreferences.findWhat + " changed to -> " + app.changeTextPreferences.changeTo + " on pages " + pageNumbers.join(',');
              

               

              Peter

              • 4. Re: Page number of replaced text
                bradsdb Level 1

                This works perfectly now. Thanks for all your help Peter!

                • 5. Re: Page number of replaced text
                  bradsdb Level 1

                  Bonus question: is there a way to either skip any text frames that are off the artboard or to include them? Basically any solution other than it giving a "null is not an object" error?

                  • 6. Re: Page number of replaced text
                    Peter Kahrel Adobe Community Professional & MVP
                    var pageNumbers = [];
                    for (var i = 0; i < myFoundItems.length; i++) {
                       if (myFoundItems[i].parentTextFrames[0].isValid){
                          pageNumbers.push (myFoundItems[i].parentTextFrames[0].parentPage.name);
                       }
                    }
                    

                     

                    Peter

                    • 7. Re: Page number of replaced text
                      bradsdb Level 1

                      I get the error below still:

                      • 8. Re: Page number of replaced text
                        Peter Kahrel Adobe Community Professional & MVP

                        Ok, try this:

                         

                        app.selection[0].parentPage == null
                        var pageNumbers = [];
                        for (var i = 0; i < myFoundItems.length; i++) {
                           if (myFoundItems[i].parentTextFrames[0].parentPage != null){
                              pageNumbers.push (myFoundItems[i].parentTextFrames[0].parentPage.name);
                           }
                        }
                        

                         

                        Peter

                        1 person found this helpful
                        • 9. Re: Page number of replaced text
                          bradsdb Level 1

                          This version works, however it requires a text frame to be selected (which then works correctly and searches the whole document) or it gives an error "undefined is not an object". This way will work though if it's a choice between this and always getting an error for off-page text frames.

                          • 10. Re: Page number of replaced text
                            Peter Kahrel Adobe Community Professional & MVP

                            That line

                            app.selection[0].parentPage == null

                            hung on from my test. Just delete it.

                            1 person found this helpful
                            • 11. Re: Page number of replaced text
                              bradsdb Level 1

                              Perfect now, thanks again!