1 Reply Latest reply on Mar 6, 2015 11:37 AM by Peter Kahrel

    in text frame enumeration

    hamdifem Level 1

      while in a text frame some numbers again I want to sort

      I have written a code for it

      but completely fails

      please help

       

      before

      2.          auto se none furor patidit

      3.          bus se none furor patidit

      7.          car se none furor patidit

       

      after

      1.          auto se none furor patidit

      2.          bus se none furor patidit

      3.          car se none furor patidit


      This process is not for the entire document

      While in a text frame or text frame is selected I want


       

      
      var sno = 0;
      app.findGrepPreferences = app.changeGrepPreferences = null;  
      app.findGrepPreferences.findWhat = "^\\d+.\\t";
      for(var i = 0; i < app.selection.length; ++i) {
      var b = app.selection[i].parentStory.textFrames; //??
      for(var i = 0; i < b.length; ++i) {
      app.changeGrepPreferences.changeTo  = (++sno).toString() + ".\t";  
      b[i].changeGrep();
      }
      }
      app.findGrepPreferences = app.changeGrepPreferences = null;  
      
        • 1. Re: in text frame enumeration
          Peter Kahrel Adobe Community Professional & MVP

          You were looking for the wrong text. Look just for the initial number, ^\d+, nothing else. Then use the loop counter to change the numbers, as in this code:

           

          app.findGrepPreferences = null;
          app.findGrepPreferences.findWhat = '^\\d+'
          numbers = app.selection[0].parentStory.findGrep();
          for (i = numbers.length-1; i >= 0; i--) {
              numbers[i].contents = String(i+1)
          }
          

           

          Select the frame that holds your text and run the script.

           

          Peter