3 Replies Latest reply on Sep 7, 2015 9:29 AM by Peter Kahrel

    parent story numbering

    hamdifem Level 1

      I am working on a test book

      We are making arrangements in the answer key

      Dropping a few questions, or changing location

      before: 1-C 2-E 4-5-C 6-B 7-C 8-C 9-B 10-C

      after:    1-C 2-E 3-4-C 5-B 6-C 7-B 8-C 9-C

      I need it again later numbering

      how a code can be written

       

       

      var no = 1;
      
      
      app.findGrepPreferences = app.changeGrepPreferences = null;       
      var xx = app.findGrepPreferences.findWhat = "(\\d+)(\\-)(\\u)";
      for(var i=0;i<xx.lenght;i++){ 
      app.changeGrepPreferences.changeTo = i + "$2$3";
      app.selection[0].parentStory.changeGrep();  
      }
      app.findGrepPreferences = app.changeGrepPreferences = null;
      
        • 1. Re: parent story numbering
          Peter Kahrel Adobe Community Professional & MVP

          Any particular reason why the first two (1-C and 2-E) aren't changed?

          • 2. Re: parent story numbering
            hamdifem Level 1

            all changed

            before : 1-C 2-E 4-A 5-C 6-B 7-C 8-C 9-B 10-C

            run script finaly

            9-C 9-E 9-A 9-C 9-B 9-C 9-C 9-B 9-C


            but I write new code and try


            var sno = 0;

            app.findGrepPreferences = null;

            app.findGrepPreferences.findWhat = "(\\d+)(\\-)";

            var founds = app.selection[0].parentStory.findGrep();

            for(k = 0; k < founds.length; ++k) {

                founds[k].contents = (++sno) + "-";

            }

            app.findGrepPreferences = app.changeGrepPreferences = null;

             

            finaly: 1-C 2-E 3-A 4-C 5-B 6-C 7-C 8-B 9-C

            • 3. Re: parent story numbering
              Peter Kahrel Adobe Community Professional & MVP

              Not sure what you mean by all this. Does your new code work? And what does 'sno' stand for?

               

              To substract 1 from all numbers preceding capitals you can use this:

               

              app.findGrepPreferences = null;
              app.findGrepPreferences.findWhat = '\\d[-\\d]+\\u';
              found = app.selection[0].findGrep();
              for (i = found.length-1; i >= 0; i--) {
                found[i].contents = found[i].contents.replace (/(\d+)/, function() {return Number(arguments[1])-1;});
              }
              

               

              Peter