Skip to main content
Obi-wan Kenobi
Legend
March 26, 2016
Question

Find frames and resize them! …

  • March 26, 2016
  • 1 reply
  • 590 views

Hi,

This simple script works fine:

var myTF = app.activeDocument.textFrames.everyItem().getElements()

for(i=0; i<myTF .length; i++)

{

    myStoreBounds = myTF.geometricBounds

    myTF.geometricBounds = [myStoreBounds[0], myStoreBounds[1], myStoreBounds[0] +50, myStoreBounds[1] +50]

}

But not this one:

var myWidth = "50 mm"

var myHeight = "50 mm"

app.activeDocument.textFrames.everyItem().resize( 

      CoordinateSpaces.INNER_COORDINATES,

      AnchorPoint.CENTER_ANCHOR,

      ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,

      [ myWidth, myHeight ]

);

I'm curious to know why! 

What I truly want to do is: select several graphic frames (not a find/replace and not text frames) and resize them using this: AnchorPoint.CENTER_ANCHOR

Another way would be to find graphic frames by their color [e.g. "Red"].

Thanks for your help and your lenience! 

This topic has been closed for replies.

1 reply

Peter Kahrel
Community Expert
Community Expert
March 26, 2016

.resize() takes as input only numbers and they are always interpreted as points. To use millimeters, convert them to points:

var myWidth = UnitValue('50mm').as('pt');

var myHeight = UnitValue('50mm').as('pt');

To select several frames and resize them, you could do something like this:

for (i = 0; i < app.selection; i++) {

  app.selection.resize(. . .);

}

Peter

Obi-wan Kenobi
Legend
March 26, 2016

Hi Peter,

Thanks for your help!

About the first point, this works fine!    So the 2 versions are OK.

2 last questions about their writing:

• If I only want to treat graphic or undefined frames, I only found this but I don't really understand if good and how to insert them in the code:


ObjectTypes.ALL_FRAMES_TYPE    All frame types.

ObjectTypes.GRAPHIC_FRAMES_TYPE    Graphics frame.

ObjectTypes.TEXT_FRAMES_TYPE    Text frame.

ObjectTypes.UNASSIGNED_FRAMES_TYPE    Unassigned frame.

• In this version, where can I add "AnchorPoint.CENTER_ANCHOR" to resize correctly the blocks?

var myTF = app.activeDocument.textFrames.everyItem().getElements()

for(i=0; i<myTF .length; i++)

{

    myStoreBounds = myTF.geometricBounds

    myTF.geometricBounds = [myStoreBounds[0], myStoreBounds[1], myStoreBounds[0] +50, myStoreBounds[1] +50]

}

About the second point, It doesn't work! Surely something I've not understood!

I've selected some blocks and tried this:

var myWidth = UnitValue('10mm').as('pt');

var myHeight = UnitValue('10mm').as('pt');

for (i = 0; i < app.selection; i++) {

  app.selection.resize(

      CoordinateSpaces.INNER_COORDINATES,

      AnchorPoint.CENTER_ANCHOR,

      ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,

      [ myWidth, myHeight ]);

}

Thanks!

Peter Kahrel
Community Expert
Community Expert
March 26, 2016

Sorry, in that code, the for loop is wrong, it should be like this:

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