3 Replies Latest reply on Aug 30, 2016 2:25 AM by Loic.Aigon

    Current Page Number marker to plain number script help

    Dimitra.p

      I 've found this script that can convert Current Page Number markers to plain numbers and it works well but on some documents it gives me an error and cannot run.

       

      main();
      function main(){
        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
      
        app.findGrepPreferences.findWhat="~N";
      
        var FindGrep=app.activeDocument.findGrep();
        for(i=0; i<FindGrep.length; i++)
        {
        var item = FindGrep[i];
        var page = item.parentTextFrames[0].parentPage;
        item.contents = page.name;
        }
      
        alert("done");
      
      }
      

       

      The error I get is the following:

       

      The Current Page Markers are not Master Page elements but run with the text of the document on purpose.

       

      What could be causing this? Is anyone more familiar with JavaScript that is able to help?

        • 1. Re: Current Page Number marker to plain number script help
          tpk1982 Level 4

          It works fine for me.. but clearing the grep search also important.. i included master page option too.. try this

           

          main();  
          function main(){  
            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;  
          app.findChangeGrepOptions.includeMasterPages = true;
          app.findGrepPreferences = null;     app.changeGrepPreferences = null;  
          
          
            app.findGrepPreferences.findWhat="~N";  
            
            var FindGrep=app.activeDocument.findGrep();  
            for(i=0; i<FindGrep.length; i++)  
            {  
            var item = FindGrep[i];  
            var page = item.parentTextFrames[0].parentPage;  
            item.contents = page.name;  
            }  
           app.findGrepPreferences = null;     app.changeGrepPreferences = null;  
          
            alert("done");  
            
          }  
          

           

           

          Thanks,

          K

          • 2. Re: Current Page Number marker to plain number script help
            Dimitra.p Level 1

            OK, I've found what was causing this. I had a text box on the pasteboard that had the current page number applied (it read as PB) and once I deleted it the script worked.

             

            Thanks for the input of clearing the GREP search before running the rest of the script.

            • 3. Re: Current Page Number marker to plain number script help
              Loic.Aigon Adobe Community Professional

              OK, I've found what was causing this. I had a text box on the pasteboard that had the current page number applied (it read as PB) and once I deleted it the script worked.

              That's because parentPage is null when the object is indeed on the pasteboard. Always useful to check the value of that property is not null before trying to use it.