Adobe 27510753 Scripting Guide - Page 77

Modular programming support, Preprocessor directives

Page 77 highlights

Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features 69 If one operand is unitValue object and the other is a number, the operation is applied to the number and the numeric value of the object. The expression returns a new unitValue object with the result as its value. For example: val = new UnitValue ("10 cm"); res = val * 20; // res is a UnitValue (200, "cm"); If both operands are unitValue objects, JavaScript converts the right operand to the same unit as the left operand and applies the operation to the resulting values. The expression returns a new unitValue object with the unit of the left operand, and the result value. For example: a = new UnitValue ("1 m"); b = new UnitValue ("10 cm"); a + b; // res is a UnitValue (1.1, "m"); b + a; // res is a UnitValue (110, "cm"); l Comparisons If one operand is a unitValue object and the other is a number, JavaScript compares the number with the unitValue's numeric value. If both operands are unitValue objects, JavaScript converts both objects to the same unit, and compares the converted numeric values. For example: a = new UnitValue ("98 cm"); b = new UnitValue ("1 m"); a < b; // => true a < 1; // => false a == 98; // => true Modular programming support ExtendScript provides support for a modular approach to scripting by allowing you to include one script in another as a resource, and allowing a script to export definitions that can be imported and used in another script. Preprocessor directives ExtendScript provides preprocessor directives for including external scripts, naming scripts, specifying an ExtendScript engine, and setting certain flags. You can specify these in two ways: l With a C-style statement starting with the # character: #include "file.jsxinc" l In a comment whose text starts with the @ character: // @include "file.jsxinc" When a directive takes one or more arguments, and an argument contains any nonalphanumeric characters, the argument must be enclosed in single or double quotes. This is generally the case with paths and file names, for example, which contain dots and slashes.

  • 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
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184

Adobe InDesign CS2 Scripting Guide
Using ExtendScript Tools and Features
69
If one operand is
unitValue
object and the other is a number, the operation is applied to the number
and the numeric value of the object. The expression returns a new
unitValue
object with the result as its
value
. For example:
val = new UnitValue ("10 cm");
res = val * 20;
// res is a UnitValue (200, "cm");
If both operands are
unitValue
objects, JavaScript converts the right operand to the same unit as the
left operand and applies the operation to the resulting values. The expression returns a new
unitValue
object with the unit of the left operand, and the result
value
. For example:
a = new UnitValue ("1 m");
b = new UnitValue ("10 cm");
a + b;
// res is a UnitValue (1.1, "m");
b + a;
// res is a UnitValue (110, "cm");
Comparisons (
=
,
==
,
<
,
>
,
<=
,
>=
)
If one operand is a
unitValue
object and the other is a number, JavaScript compares the number with
the
unitValue
’s numeric value.
If both operands are
unitValue
objects, JavaScript converts both objects to the same unit, and compares
the converted numeric values.
For example:
a = new UnitValue ("98 cm");
b = new UnitValue ("1 m");
a < b;
// => true
a < 1;
// => false
a == 98; // => true
Modular programming support
ExtendScript provides support for a modular approach to scripting by allowing you to include one script in
another as a resource, and allowing a script to export definitions that can be imported and used in another
script.
Preprocessor directives
ExtendScript provides preprocessor directives for including external scripts, naming scripts, specifying an
ExtendScript engine, and setting certain flags. You can specify these in two ways:
With a C-style statement starting with the
#
character:
#include "file.jsxinc"
In a comment whose text starts with the
@
character:
// @include "file.jsxinc"
When a directive takes one or more arguments, and an argument contains any nonalphanumeric characters,
the argument must be enclosed in single or double quotes. This is generally the case with paths and file
names, for example, which contain dots and slashes.
l
l
l