Adobe 65014293 Scripting Guide - Page 57

Using unit values in calculations, Unit value usage

Page 57 highlights

CHAPTER 3: Scripting Photoshop Working with Units 57 The values returned for a Photoshop property that uses units is returned as a value of the current ruler type. Getting the height of the document created above: set docHeight to height of current document returns a value of 5.0, which represents 5 inches based on the current ruler settings. In AppleScript, you can optionally ask for a property value as a particular type. set docHeight to height of current document as points This returns a value of 360 (5 inches x 72 points per inch). The points and picas unit value types are PostScript points, with 72 points per inch. The traditional points and traditional picas unit value types are based on classical type setting values, with 72.27 points per inch. You can convert, or coerce, a unit value from one value type to another. For example, the following script converts a point value to an inch value. set pointValue to 72 as points set inchValue to pointValue as inches When this script is run, the variable inchValue will contain inches 1, which is 72 points converted to inches. This conversion ability is built in to the AppleScript language. NOTE: The unit values cm units and mm units cannot be used in this way with a corresponding reference to cm or mm. They are not supported by the AppleScript terminology. Using unit values in calculations To use a unit value in a calculation in Applescript 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) * 5 NOTE: In AppleScript you can get and set values as pixels or percent as you would any other unit value type. You cannot, however, convert a pixel or percent value to another length unit value as you can with other length value types. Trying to run the following script will result in an error. set pixelValue to 72 as pixels -- Next line will result in a coercion error when run set inchValue to pixelValue as inches NOTE: Because Photoshop is a pixel-oriented application you may not always get back the same value as you pass in when setting a value. For example, if ruler units is set to mm units, and you create a document that is 30 x 30, the value returned for the height or width will be 29.99 if your document resolution is set to 72 ppi. The scripting interface assumes settings are measured by ppi. 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.

  • 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

C
HAPTER
3: Scripting Photoshop
Working with Units
57
The values returned for a Photoshop property that uses units is returned as a value of the current ruler
type. Getting the height of the document created above:
set docHeight to height of current document
returns a value of 5.0, which represents 5 inches based on the current ruler settings.
In AppleScript, you can optionally ask for a property value as a particular type.
set docHeight to height of current document as points
This returns a value of 360 (5 inches x 72 points per inch).
The
points
and
picas
unit value types are PostScript points, with 72 points per inch. The
traditional
points
and
traditional
picas
unit value types are based on classical type setting values, with 72.27
points per inch.
You can convert, or coerce, a unit value from one value type to another. For example, the following script
converts a point value to an inch value.
set pointValue to 72 as points
set inchValue to pointValue as inches
When this script is run, the variable
inchValue
will contain inches 1, which is 72 points converted to
inches. This conversion ability is built in to the AppleScript language.
N
OTE
:
The unit values
cm
units
and
mm
units
cannot be used in this way with a corresponding reference
to
cm
or
mm
. They are not supported by the AppleScript terminology.
Using unit values in calculations
To use a unit value in a calculation in Applescript 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) * 5
N
OTE
:
In AppleScript you can get and set values as pixels or percent as you would any other unit value
type. You cannot, however, convert a pixel or percent value to another length unit value as you can with
other length value types. Trying to run the following script will result in an error.
set pixelValue to 72 as pixels
-- Next line will result in a coercion error when run
set inchValue to pixelValue as inches
N
OTE
:
Because Photoshop is a pixel-oriented application you may not always get back the same value as
you pass in when setting a value. For example, if
ruler
units
is set to mm units, and you create a
document that is 30 x 30, the value returned for the height or width will be 29.99 if your document
resolution is set to 72 ppi. The scripting interface assumes settings are measured by ppi.
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.