Adobe 0046100128056 Scripting Guide - Page 56

Working with Items, Creating Items

Page 56 highlights

5 Working with Page Items This chapter covers scripting techniques related to the page items (rectangles, ellipses, graphic lines, polygons, text frames, buttons, and groups) that can appear in an InDesign layout. This document discusses the following: X Creating page items. X Page item geometry. X Working with paths and path points X Creating groups. X Duplicating and moving page items. X Transforming page items. Creating Page Items Page items in an InDesign layout are arranged in a hierarchy, and appear within a container object of some sort. Spreads, pages, other page items, groups, and text characters are all examples of objects that can contain page items. This hierarchy of containers in the InDesign scripting object model is the same as in the InDesign user interface--when you create a rectangle by dragging the Rectangle tool on a page, you are specifying that the page is the container, or parent, of the rectangle. When you paste an ellipse into a polygon, you are specifying that the polygon is the parent of the ellipse, which, in turn, is a child object of its parent, a page. In general, creating a new page item is as simple as telling the object you want to contain the page item to create the page item, as shown in the MakeRectangle script. //Given a page "myPage", create a new rectangle at the default size and location... var myRectangle = myPage.rectangles.add(); In the above script, a new rectangle is created on the first page of a new document. The rectangle appears at the default location (near the upper left corner of the page) and has a default size (around ten points square). Moving the rectangle and changing its dimensions are both accomplished by filling its geometric bounds property with new values, as shown in the MakeRectangleWithProperties script. //Given a page "myPage", create a new rectangle and specify its size and location... var myRectangle = myPage.rectangles.add({geometricBounds:[72, 72, 144, 144]}); Page item types It is important to note that you cannot create a "generic" page item--you have to create a page item of a specific type (a rectangle, oval, graphic line, polygon, text frame, or button). You will also notice that InDesign changes the type of a page item as the geometry of the page item changes. A rectangle, for example, is always made up of a single, closed path containing four path points and having 90 degree interior angles. Change the location of a single point, however, or add another path, and the type of the page item changes to a polygon. Open the path and remove two of the four points, and InDesign will 56

  • 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

56
5
Working with Page Items
This chapter covers scripting techniques related to the page items (rectangles, ellipses, graphic lines,
polygons, text frames, buttons, and groups) that can appear in an InDesign layout.
This document discusses the following:
X
Creating page items.
X
Page item geometry.
X
Working with paths and path points
X
Creating groups.
X
Duplicating and moving page items.
X
Transforming page items.
Creating Page Items
Page items in an InDesign layout are arranged in a hierarchy, and appear within a
container
object of some
sort. Spreads, pages, other page items, groups, and text characters are all examples of objects that can
contain page items. This hierarchy of containers in the InDesign scripting object model is the same as in
the InDesign user interface--when you create a rectangle by dragging the Rectangle tool on a page, you
are specifying that the page is the container, or
parent
, of the rectangle. When you paste an ellipse into a
polygon, you are specifying that the polygon is the parent of the ellipse, which, in turn, is a
child
object of
its parent, a page.
In general, creating a new page item is as simple as telling the object you want to contain the page item to
create the page item, as shown in the MakeRectangle script.
//Given a page "myPage", create a new rectangle at the default size and location...
var myRectangle = myPage.rectangles.add();
In the above script, a new rectangle is created on the first page of a new document. The rectangle appears
at the default location (near the upper left corner of the page) and has a default size (around ten points
square). Moving the rectangle and changing its dimensions are both accomplished by filling its geometric
bounds property with new values, as shown in the MakeRectangleWithProperties script.
//Given a page "myPage", create a new rectangle and specify its size and location...
var myRectangle = myPage.rectangles.add({geometricBounds:[72, 72, 144, 144]});
Page item types
It is important to note that you cannot create a “generic” page item--you have to create a page item of a
specific type (a rectangle, oval, graphic line, polygon, text frame, or button). You will also notice that
InDesign changes the type of a page item as the geometry of the page item changes. A rectangle, for
example, is always made up of a single, closed path containing four path points and having 90 degree
interior angles. Change the location of a single point, however, or add another path, and the type of the
page item changes to a polygon. Open the path and remove two of the four points, and InDesign will