1 Reply Latest reply on Nov 19, 2014 2:17 PM by RobertKyle

    Can I use script to move a text box to a spesific coordinate, and change the width of this box?

    espenmoe Level 1

      I'm looking for a quick way to move a text box fra coordinate x/y to coordinate a/b - and changing it from 200 pixel width to 680. From within an image, to just beneath it.

      Ihave the same template for several pages (daily newspaper), and this operation is going to be done a lot during the week. If this can be done using a script, I can assign a keystroke to this script, and then move/change the text block with one quick keyboard shortcut.


      Is it possible?

        • 1. Re: Can I use script to move a text box to a spesific coordinate, and change the width of this box?
          RobertKyle Level 2

          Here are some snippets that might help:


          // step 1: change document rulers to pixels, to make the math easier

          app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.PIXELS;

          app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.PIXELS;


          // step 2: move the selected box to your new coordinates. Here, x comes first



          // get an array containing the bounds of the text frame

          var frameBounds = app.selection[0].geometricBounds;

          //  calculate the new X2 coordinate and insert it into the array

          frameBounds[3] = 200 + frameBounds[1];

          // apply the new array to the selected frame

          app.selection[0].geometricBounds = frameBounds;


          It's considered good form to reset the measurement units to their previous state. But maybe you want all pages in pixels. I usually work in points and I hear complains when one of my scripts fails to restore the designer's preferred ruler.


          The "move" command works relative to the ruler origin, which can also be controlled by script if that's an issue. We use pages with margins, so I set "app.activeDocument.zeroPoint" to the top and left margins.


          If you're going to put this into the hands of a lot of users, you'll want to do some checking to make sure a textFrame is selected before anything else happens. app.selection[0] could be a lot of different things.