3 Replies Latest reply on May 17, 2016 12:39 AM by Loic.Aigon

    Can someone simplify this script


      Hi All,


      I just write this script move text frames with script labels of page 1 in my document. I felt that this is something simple but having lot of loop with in it. Is there any way to simplify it by catch the text frame directly in secon and third loops.



      var jt=app.activeDocument.pages[0].textFrames;
      for (i=0;i<jt.length;i++)
      if ((jt[i].label=="Label1"))
          alert (jt[i].geometricBounds[2]);
          var jt1=app.activeDocument.pages[0].textFrames;
          for (j=0;j<jt.length;j++)
                  if ((jt1[j].label=="Label2"))
                          var jt2=app.activeDocument.pages[0].textFrames;
                              for (k=0;k<jt.length;k++)
                                  if ((jt2[k].label=="Label3"))


      My layout as below:


        • 1. Re: Can someone simplify this script
          S Hopkins Adobe Community Professional

          Not too sure if this is what you want. With an attempt to figure out your logic:

          First within a loop of all of your text frames, create 3 arrays:

          (1)  x1Array = All with Label1 and geometricBounds[2] > 153

          (2)  x2Array = All with Label2

          (3) x3Array - All with Label3

          Then within a loop of the x1Array items, adjust the geometric bounds for all items in the x2Array and x3Arrays

          Not any simpler, but easier to follow and smaller arrays to loop through.

          It will be interesting to see what others come up with.

          var x1Array = [];

          var x2Array= [];

          var x3Array = [];

          var iBounds, jBounds, newjBounds, kBounds, newkBounds


          //create array of items by label


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

              if (it[i].label=="Label1") {

                  iBounds = it[i].geometricBounds;

                  if (iBounds[2] > 153) {

                      alert ("test " + iBounds[2]);



              } else if (it[i].label=="Label2") {


              } else if (it[i].label=="Label3") {




          //loop through x1Array and adjust bounds for other items

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

              iBounds = x1Array[i].geometricBounds;

              for (var j = 0; j < x2Array.length; j++) {

                  jBounds = x2Array[j].geometricBounds;

                  newjBounds = [(iBounds[2]+25), jBounds[1], (iBounds[2]+48), jBounds[3]];

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

                   kBounds = x3Array[k].geometricBounds;

                   newkBounds = [newjBounds[0], newjBounds[1], kBounds[2], kBounds[3]];




          • 2. Re: Can someone simplify this script
            Peter Kahrel Adobe Community Professional & MVP

            An alternative is as follows: frames are offset to the right, the offset is determined by the value of the label. You can then move each frame to the right using the offset:


            jt = app.activeDocument.pages[0].textFrames;
            for (i = 0; i < jt.length; i++) {
              offset = jt[i].name.match (/\d+$/)[0];
              jt[i].move (undefined, [offset*100, 0]);



            • 3. Re: Can someone simplify this script
              Loic.Aigon Adobe Community Professional

              I second Peter's approach. The best way to make scripts "simple" is actually not to code anything until you get a sufficient hindsight to consider your problem in a generic way. Once you can resume your issue to a generic approach, it's easier to write down generic and reusable code.