Working With Units - Adobe 23101764 - Photoshop CS - PC Manual

Scripting guide
Hide thumbs Also See for 23101764 - Photoshop CS - PC:
Table of Contents

Advertisement

Scripting Photoshop
3

Working with units

The following example shows how to create 2 layers and then rename the first one in
JavaScript.
// set ruler units and create new document
originalRulerUnits = app.preferences.rulerUnits
app.preferences.rulerUnits = Units.INCHES;
app.documents.add(4,4,72,"My New Document");
docRef = app.activeDocument;
layer1Ref = docRef.artLayers.add();
layer2Ref = docRef.artLayers.add();
layer1Ref.name = "This layer was first";
// restore unit setting
app.preferences.rulerUnits = originalRulerUnits;
3.6 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.6.1 Unit values
Photoshop uses unit values for certain properties and parameters. Scripting comments
concerning Photoshop objects and properties note where unit values are used.
Because of scripting language differences, the way you provide a unit value in a script depends
on the language you are using. All languages support plain numbers for unit values. These
values are treated 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 is 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
57
Photoshop CS Scripting Guide

Advertisement

Table of Contents
loading

This manual is also suitable for:

Photoshop cs

Table of Contents