
Photoshop 7.0 Scripting Guide
44
Scripting Photoshop
Working with units
3
3.5 Working with units
Photoshop provides two rulers for use when working on a document — a graphics ruler used
for most graphical layout measurements and a type ruler which is active when using the type
tool. The unit types for these two rulers are set using the
ruler units
(RulerUnits/rulerUnits)
and
type units (TypeUnits/typeUnits)
, respectively.
These settings correspond to those found in the Photoshop preference dialog under “Edit
>Preferences > Units & Rulers.”
The graphics ruler is used for most operations on a document where height, width, or position
are specified. The type ruler is used when operating on text items, such as when setting leading
or indent values. By changing the settings for each ruler you can work with documents in the
measurement system that make the most sense for the project at hand.
3.5.1 Unit values
Photoshop Scripting Support uses unit values for certain properties and parameters. The
comments for the Photoshop Scripting Support objects and properties will note where unit
values are used.
Because of scripting languages differences, the way you provide a unit value in a script will
depend on the language you are using. All languages support plain numbers for unit values.
Scripting Support treats these values as being of the type currently specified for the
appropriate ruler.
For example, if the ruler units are currently set to inches and the following Visual Basic
statement is executed:
docRef.ResizeImage 3,3
the document's image will be resized to 3 inches by 3 inches. If the ruler units were set to
pixels, the image would be 3 pixels by 3 pixels, which is probably not what was intended. To
ensure that your scripts produce the expected results you should check and set the ruler units to
the type appropriate for your script. After executing a script the original values of the rule
settings should be restored if changed in the script. See section
3.5.3, “Changing ruler and type
units” on page 48
for directions on setting unit values.
AppleScript unit considerations
AppleScript provides an additional way of working with unit values. You can provide values
with an explicit unit type where unit values are used. When a typed value is provided its type
overrides the ruler’s current setting.
For example, to create a document which is 4 inches wide by 5 inches high you would write:
make new document with properties {width:inches 4, ¬
height:inches 5}