
Adobe InDesign CS4 Scripting Tutorial
Scripting and the InDesign object model
24
Measurements and positioning
All items and objects in InDesign are positioned on the page according to measurements you choose. It is
useful to know how the InDesign coordinate system works and what measurement units it uses.
Coordinates
InDesign, like every other page-layout and drawing program, uses simple, two-dimensional geometry to
set the position of objects on a page or spread. The horizontal component of a coordinate pair is referred
to as
x
; the vertical component,
y
. You can see these coordinates in the Transform panel or Control when
you select an object using the Selection tool. As in the InDesign user interface, coordinates are measured
relative to the current location of the ruler’s zero point.
There is one difference between the coordinates used in InDesign and the coordinate system used in a
Geometry textbook: on InDesign’s vertical (or y) axis, coordinates
below
the zero point are positive
numbers; coordinates
above
the zero point are negative numbers.
N
OTE
:
When you ask InDesign for the location of a path point, the coordinates are returned in
x, y
order.
When you set the location of a path point, InDesign expects you to provide the coordinates in the same
order. InDesign returns some coordinates in a different order, however, and it expects you to supply them
in that order. Geometric bounds and visible bounds are arrays containing four coordinates, which define
(in order) the top, left, bottom, and right edges of the object’s bounding box (or
y1
,
x1
,
y2
,
x2
).
Working with measurement units
When you send measurement values to InDesign, you can send numbers (for example, 14.65) or
measurement strings (for example, “1p7.1”). If you send numbers, InDesign uses the publication’s current
units of measurement. If you send measurement strings (see the table below), InDesign uses the units of
measurement specified in the string.
InDesign returns coordinates and other measurement values using the publication’s current measurement
units. In some cases, these units do not resemble the measurement values shown in the InDesign
Transform panel. For example, if the current measurement system is picas, InDesign returns fractional
values as decimals, rather than using the picas-and-points notation used by the Transform panel. “1p6,” for
example, is returned as “1.5.” InDesign does this because your scripting system would have trouble trying
to perform arithmetic operations using measurement strings; for instance, trying to add “0p3.5” to “13p4”
produces a script error, while adding .2916 to 13.333 (the converted pica measurements) does not.
If your script depends on adding, subtracting, multiplying, or dividing specific measurement values, you
might want to set the corresponding measurement units at the beginning of the script. At the end of the
script, you can set the measurement units back to whatever they were before you ran the script.
Alternately, you can use measurement overrides, like many of the sample scripts. A measurement override
is a string containing a special character, as shown in the following table:
Override
Meaning
Example
c
Ciceros (add didots after the c, if necessary)
1.4c
cm
Centimeters
.635cm
i (or in)
Inches
.25i
mm
Millimeters
6.35mm