Adobe 23101764 Scripting Guide - Page 61

Working with units

Page 61 highlights

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 Photoshop CS Scripting Guide 57

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105

Photoshop CS Scripting Guide
57
Scripting Photoshop
Working with units
3
The following example shows how to create 2 layers and then rename the
rst 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 speci
ed. 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 speci
ed 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