Resizing all my frames at once by a certain amount

Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Resizing all my frames at once by a certain amount

Viewing 2 reply threads
  • Author
    Posts
    • #1223978
      Mark Guest
      Member

      I am new to InDesign Secrets and new to scripts, so I have not fully searched the site. Can anyone point me to a script that will perform the following:
      I have been tasked to take an old brochure and make large scale edits to it.
      One of the tasks is to put a border between pictures that fit next to each other. I want to be able to grab a number of frames and automatically resize them either top & bottom OR left and right by 1/8″ creating a small border between each.

      Is this possible? Is there a script out there that does this? How do I write one that will do this?

      If not is there another way of accomplishing this task?

      Thanks for your help in advance.

    • #14323248
      Brian Pifer
      Participant

      Hi Mark,

      You can try this script: https://raw.githubusercontent.com/jpobojewski/InDesign-Toolbox/master/Resize%20Selected%20Items.jsx

      You can also select all the objects you want, and set the anchor point to the top center or left center point (the grid in properties), then type -.25 in the W (width) property.

      If you want to roll your own, here’s how to get started:

      This line of code will get you the current selection as an “array”, meaning you can select multiple text frames and iterate through them.

      var selections = app.selection;

      The iteration looks like this:

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

      }

      Inside the bracket, you’ll want to get the frame’s coordinates and use either resize or reframe. This part is a bit complicated, but essentially you are using the “resolve” method of a frame to get its current coordinates, then performing math on those coordinates and using resize or reframe using points (9 points = .125 in).
      var frame = selections[i];
      var topleft = frame.resolve(AnchorPoint.TOP_LEFT_ANCHOR, CoordinateSpaces.INNER_COORDINATES, true)[0];
      var bottomright = frame.resolve(AnchorPoint.BOTTOM_RIGHT_ANCHOR, CoordinateSpaces.INNER_COORDINATES, true)[0];
      var x1 = topleft[0] + 9;
      var y1 = topleft[1];
      var x2 = bottomright[0] – 9;
      var y2 = bottomright[1];
      frame.reframe(CoordinateSpaces.INNER_COORDINATES, [[x1, y1], [x2, y2]], true);

      In that math, you are moving the x1 coordinate inward by 9 points (.125 in) and shrinking the x2 coordinate by .125. If you to change the height, you’d do the same operations on the y coordinates.

      The full code put together:

      var selections = app.selection;
      for (var i = 0; i < selections.length; i++) {
      var frame = selections[i];
      var topleft = frame.resolve(AnchorPoint.TOP_LEFT_ANCHOR, CoordinateSpaces.INNER_COORDINATES)[0];
      var bottomright = frame.resolve(AnchorPoint.BOTTOM_RIGHT_ANCHOR, CoordinateSpaces.INNER_COORDINATES)[0];
      var x1 = topleft[0] + 9;
      var y1 = topleft[1];
      var x2 = bottomright[0] – 9;
      var y2 = bottomright[1];
      frame.reframe(CoordinateSpaces.INNER_COORDINATES, [[x1, y1], [x2, y2]]);
      }

      This also assumes you don’t need to resize the containing images after the resize. There’s lots of things that go into writing a script to do what you want to do, but hope this gives you a good starting point for understanding.

    • #14323245
      Mark Guest
      Member

      Thanks for the response, Brian. I’ll try it.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
>