Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Adobe Photoshop > Technique

  • Print
  • + Share This
This chapter is from the book

Working with units

Adobe Photoshop CS2 provides two rulers for documents. You can set the measurement units for the rulers in your script. The rulers are:

  • A graphics ruler used for most graphical layout measurements or operations on a document where height, width, or position are specified.

    You set measurement unit types for the graphics ruler using the rulerUnits property.

  • A type ruler, which is active when using the type tool

    You set measurement unit types for the type ruler using the typeUnits property.

Unit values

All languages support plain numbers for unit values. These values are treated as being of the type currently specified for the appropriate ruler.

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 “Setting ruler and type units in a script” on page 49 for directions on setting unit values.

Please refer to Adobe Photoshop CS2 Help for information about available unit value types.

Special unit value types

The unit values used by Adobe Photoshop CS2 are length units, representing values of linear measurement. Support is also included for pixel and percent unit values. These two unit value types are not, strictly speaking, length values but are included because they are used extensively by Adobe Photoshop CS2 for many operations and values.

Using unit values in calculations

To use a unit value in a calculation it is necessary to first convert the value to a number (unit value cannot be used directly in calculations). To multiply an inch value write:

set newValue to (inchValue as number) * someValue

Unit value usage

The following tables list the properties of the classes/objects that are defined to use unit values. Unit values for these properties, unless otherwise indicated in the table, are based the graphics ruler setting.

To use this table, look up the property in the object’s Properties table in Part 2 of this book.


JavaScript Properties



EPS open options


PDF open options


lens flare open options


offset filter


Text Item

baselineShift [*]
firstLineIndent [1]
hyphenationZone [1]
leading [1]
leftIndent [1]
rightIndent [1]
spaceBefore [1]
spaceAfter [1]

The following list contains the methods that use unit values as parameters or arguments. In some cases the parameters are required. The methods are preceded by the object to which they belong. Look up the method in the Methods table of the object in the “Interface” chapter in Part 2 of this book.

  • document.crop(bounds, height, width)
  • document.resizeCanvas(height, width)
  • document.resizeImage(height, width)
  • selection.contract(by)
  • selection.expand(by)
  • selection.feather(by)
  • selection.selectBorder(width)
  • selection.translate(deltaX, deltaY)
  • selection.translateBoundary(deltaX, deltaY)

Setting ruler and type units in a script

The unit type settings of the two Adobe Photoshop CS2 rulers control how numbers are interpreted when dealing with properties and parameters that support unit values. Be sure to set the ruler units as needed at the beginning of your scripts and save and restore the original ruler settings when your script has completed.

In JavaScript ruler units and type units are properties of the Preferences, accessed through the Application object’s preferences property as shown below.

app.preferences.rulerUnits = Units.INCHES
app.preferences.typeUnits = TypeUnits.PIXELS
app.preferences.pointSize = PointType.POSTSCRIPT
  • + Share This
  • 🔖 Save To Your Account