Adobe 23101764 Scripting Guide - Page 63

Special unit value types

Page 63 highlights

Scripting Photoshop 3 Working with units 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. When working with unit values, it is possible to convert, or coerce, a unit value from one value type to another. For example, the following script will convert a point value to an inch value. set pointValue to points 72 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. 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 Special unit value types The unit values used by Photoshop 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 Photoshop for many operations and values. 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 pixels 72 -- Next line will result in a coercion error when run set inchValue to pixelValue as inches Photoshop CS Scripting Guide 59

  • 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
59
Scripting Photoshop
Working with units
3
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.
When working with unit values, it is possible to convert, or coerce, a unit value from one value
type to another. For example, the following script will convert a point value to an inch value.
set pointValue to points 72
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.
To use a unit value in a calculation it is necessary to
rst 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
Special unit value types
The unit values used by Photoshop 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 Photoshop for many operations and values.
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 pixels 72
-- Next line will result in a coercion error when run
set inchValue to pixelValue as inches