Adobe 0046100128056 Scripting Guide - Page 58

Working with paths and path points

Page 58 highlights

CHAPTER 5: Working with Page Items Creating Page Items 58 X Changing the zero point location by either dragging the zero point or by changing the ruler origin changes the coordinates on the rulers. X Page items are made up of one or more paths, which, in turn, are made up of two or more path points. Paths can be open or closed. X Path points contain an anchor point (the location of the point itself ) and two control handles (left direction, which controls the curve of the line segment preceding the point on the path; and right direction, which controls the curve of the segment following the point). Each of these properties contains an array in the form (x, y) (where x is the horizontal location of the point, and y is the vertical location). This array holds the location, in current ruler coordinates, of the point or control handle. All of the above means that if your scripts need to construct page items, you also need to control the location of the zero point, and you may want to set the measurement units in use. Working with paths and path points For most simple page items, you do not need to worry about the paths and path points that define the shape of the object. Rectangles, ellipses, and text frames can be created by specifying their geometric bounds, as we did in the earlier example in this chapter. In some cases, however, you may want to construct or change the shape of a path by specifying path point locations, you can either set the anchor point, left direction, and right direction of each path point on the path individually (as shown in the DrawRegularPolygon_Slow script), or you can use the entirePath property of the path to set all of the path point locations at once (as shown in the DrawRegularPolygon_Fast script). The latter approach is much faster. The items in the array you use for the entirePath property can contain anchor points only, or a anchor points and control handles. Here is an example array containing only anchor point locations: [[x1, y1], [x2, y2], ...] Where x and y specify the location of the anchor. Here is an example containing fully-specified path points (i.e., arrays containing the left direction, anchor, and right direction, in that order): [[xL1, YL1], [x1, y1], [xR1, yR1]], [[xL2, YL2], [x2, y2], [xR2, yR2]], ...] Where xL and yL specify the left direction, x and y specify the anchor point, and xR and yR specify the right direction. You can also mix the two approaches, as shown in the following example: [[[xL1, YL1], [x1, y1], [xR1, yR1]], [x2, y2], ...] Note that the original path does not have to have the same number of points as you specify in the array-InDesign will add or subtract points from the path as it applies the array to the entirePath property. The AddPathPoint script shows how to add path points to a path without using the entirePath property. //Given a graphic line "myGraphicLine"... var myPathPoint = myGraphicLine.paths.item(0).pathPoints.add(); //Move the path point to a specific location. myPathPoint.anchor = [144, 144]; The DeletePathPoint script shows how to delete a path point from a path.

  • 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
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209

C
HAPTER
5: Working with Page Items
Creating Page Items
58
X
Changing the zero point location by either dragging the zero point or by changing the ruler origin
changes the coordinates on the rulers.
X
Page items are made up of one or more paths, which, in turn, are made up of two or more path points.
Paths can be open or closed.
X
Path points contain an anchor point (the location of the point itself) and two control handles (left
direction, which controls the curve of the line segment preceding the point on the path; and right
direction, which controls the curve of the segment following the point). Each of these properties
contains an array in the form (
x
,
y
) (where
x
is the horizontal location of the point, and
y
is the vertical
location). This array holds the location, in current ruler coordinates, of the point or control handle.
All of the above means that if your scripts need to construct page items, you also need to control the
location of the zero point, and you may want to set the measurement units in use.
Working with paths and path points
For most simple page items, you do not need to worry about the paths and path points that define the
shape of the object. Rectangles, ellipses, and text frames can be created by specifying their geometric
bounds, as we did in the earlier example in this chapter.
In some cases, however, you may want to construct or change the shape of a path by specifying path point
locations, you can either set the anchor point, left direction, and right direction of each path point on the
path individually (as shown in the DrawRegularPolygon_Slow script), or you can use the entirePath
property of the path to set all of the path point locations at once (as shown in the
DrawRegularPolygon_Fast script). The latter approach is much faster.
The items in the array you use for the entirePath property can contain anchor points only, or a anchor
points and control handles. Here is an example array containing only anchor point locations:
[[x1, y1], [x2, y2], ...]
Where
x
and
y
specify the location of the anchor.
Here is an example containing fully-specified path points (i.e., arrays containing the left direction, anchor,
and right direction, in that order):
[[xL1, YL1], [x1, y1], [xR1, yR1]], [[xL2, YL2], [x2, y2], [xR2, yR2]], ...]
Where
xL
and
yL
specify the left direction,
x
and
y
specify the anchor point, and
xR
and
yR
specify the right
direction.
You can also mix the two approaches, as shown in the following example:
[[[xL1, YL1], [x1, y1], [xR1, yR1]], [x2, y2], ...]
Note that the original path does not have to have the same number of points as you specify in the
array—InDesign will add or subtract points from the path as it applies the array to the entirePath property.
The AddPathPoint script shows how to add path points to a path without using the entirePath property.
//Given a graphic line "myGraphicLine"...
var myPathPoint = myGraphicLine.paths.item(0).pathPoints.add();
//Move the path point to a specific location.
myPathPoint.anchor = [144, 144];
The DeletePathPoint script shows how to delete a path point from a path.