4 Replies Latest reply on Oct 1, 2014 5:31 AM by hamdifem

    Is it possible? with a script in a test  question numbers  automatically assign

    hamdifem Level 1

      I've got a 400-page document

      every question in the text frame and after point after the point tabs

      in text frame question numbers mixed and I want to fix as in the picture

      Image_14.jpg

        • 1. Re: Is it possible? with a script in a test  question numbers  automatically assign
          Sajeev Sridharan Level 4

          Try this,

           

          var myDoc = app.activeDocument, question_no=0;
          for(var p=0; p<myDoc.pages.length; p++)
          {
              for(var i = myDoc.pages[p].textFrames.length-1; i>=0; i--)  
              {  
                  question_no++;
                  myDoc.pages[p].textFrames[i].texts[0].select();
                  app.findGrepPreferences = app.changeGrepPreferences = null;
                  app.findGrepPreferences.findWhat = "^\\d+.\\t";
                  app.changeGrepPreferences.changeTo  = question_no + ".\t";
                  app.selection[0].changeGrep();
                  app.findGrepPreferences = app.changeGrepPreferences = null;
              }
              question_no = 1;//If you want continuous page number throughout the document, then hide this line
          }  
          

           

           

          Vandy

          • 2. Re: Is it possible? with a script in a test  question numbers  automatically assign
            hamdifem Level 1

            This script from the first text frame created numbering begins

            whereas mixed was created

            ranking first left top-down, after right the top-down is it possible to

            • 3. Re: Is it possible? with a script in a test  question numbers  automatically assign
              hamdifem Level 1

              This script from the first text frame created numbering begins

              whereas mixed was created

              ranking first left top-down, after right the top-down is it possible to

               

              the result is this happening

              Image_15.jpg

              • 4. Re: Is it possible? with a script in a test  question numbers  automatically assign
                hamdifem Level 1

                this script, one-page document, is working correctly

                but the two-page, three-page, multi-page document does not work, doing it wrong

                 

                 

                var myDoc = app.activeDocument;

                var boxA = [];

                var Qno = 0;

                myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;   

                myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;   

                myDoc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

                myDoc.zeroPoint = [0,0];

                 

                 

                var width = myDoc.documentPreferences.pageWidth; 

                var height = myDoc.documentPreferences.pageHeight; 

                 

                 

                for (p = 0; p < myDoc.pages.length; p++) 

                    for (t = 0; t<myDoc.pages[p].textFrames.length; t++) 

                    { 

                        boxA.push(myDoc.pages[p].textFrames[t]);

                    } 

                 

                 

                function boxNo(boox) {

                    var no, wh;

                    var gBounds = boox.geometricBounds; 

                   

                    var myLeftMargin = boox.parentPage.marginPreferences.left; 

                    var myRightMargin = boox.parentPage.marginPreferences.right; 

                    var liveArea = width-myLeftMargin-myRightMargin;     

                   

                    if(gBounds[1] < (liveArea/2))  {

                        no = 1;

                        wh = gBounds[0];

                    } else {

                        no = 5;

                        wh = gBounds[0];

                    }

                   

                    return ((boox.parentPage.index * 10000) + (no * 1000) + wh);

                }

                 

                 

                boxA.sort(function(a, b) {

                    return boxNo(a) - boxNo(b);

                });

                 

                 

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

                    app.findGrepPreferences = app.changeGrepPreferences = null; 

                    app.findGrepPreferences.findWhat = "^\\d+.\\t"; 

                    app.changeGrepPreferences.changeTo  = (++Qno).toString() + ".\t"; 

                    boxA[i].texts[0].changeGrep(); 

                    app.findGrepPreferences = app.changeGrepPreferences = null; 

                }