Skip to main content
Inspiring
July 2, 2015
Question

Why is PageItem.resize() unit independent? What other methods are?

  • July 2, 2015
  • 1 reply
  • 2598 views

I am continuing my journey through InDesign scripting units and values blues. I am currently trying to resize a PageItem and have found the following code resizes the selected PageItem in 'points' not my viewPreferences.horizontalMeasurementUnits, 'millimeters'.

document.selection[0].resize( CoordinateSpaces.pasteboardCoordinates, AnchorPoint.centerAnchor, ResizeMethods.ADDING_CURRENT_DIMENSIONS_TO, [ 100, 0 ] );

I am still trying to work out the best way to work with units and values of size. I thought all properties and methods used the documents viewPreferences unit properties when dealing with values of size… Turns out I was wrong!

I am asking the experienced scripters:

  1. Considering all methods that manipulate, measure, compare or return values of size, what would be the ratio of methods that are unit dependent vs unit independent be? I.e. viewPreferences vs points.
  2. If Adobe were to work on making this more consistent in the future which direction do you think they would go?

I ask so that I can pick a methodology that I feel will be simpler across a wider range of methods and possibly be more future proof.

This topic has been closed for replies.

1 reply

Community Expert
July 2, 2015

It is true that .resize() works in points only. As far as I know it's the only function that doesn't consider the document's measurement units.

Whether Adobe will ever change this I don't know. But in the meantime you can convert a value into points using JavaScript's UnitValue function. For example, suppose you have a text frame selected. Then you can get the position of the frame's top in points no matter what the document's units are using the following method:

top = app.selection[0].geometricBounds[0];

topInPoints = UnitValue(top, app.documents[0].viewPreferences.horizontalMeasurementUnits).as('pt');

It's quite a mouthful but it works.

Another method could be the use the .horizontalScale and .vericalScale properties.

Peter

McShamanAuthor
Inspiring
July 2, 2015

Hmmm thats a bit of a shame. I was kinda hoping maybe Adobe might be moving to a unit independent system. It would make more sense. It would mean as developers you wouldn't have to constantly check the users settings and you could easily combine and compare elements that typically use different unit types. E.g. PageItem geometric bounds and stroke weights.

Community Expert
July 2, 2015

The best way to deal with this is to set the script preferences so that everything is treated as points. That doesn't change the document's units, just the script-document interface:

app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;