Adobe 27510753 Scripting Guide - Page 23

Control structures, Conditional statements

Page 23 highlights

Adobe InDesign CS2 Scripting Guide Scripting Basics 15 AppleScript In AppleScript, you can also use the "with properties" to specify object properties as the object is created. tell application "Adobe InDesign CS2" --Example of an optional parameter (requires that you have a document preset --named "7x9_book_cover"). set myDocument to make document with document preset "7x9_book_cover" tell page 1 of myDocument --Example of using "with properties" to specify object properties as you create the object. set myOval to make oval with properties {geometric bounds:{"6p", "6p", "18p", "18p"}} --Another "with properties" example. set myRectangle to make rectangle with properties {stroke weight:4} --Example of a required parameter: set myGroup to make group with properties {group items:{myOval, myRectangle}} end tell end tell VBScript Set myInDesign = CreateObject("InDesign.Application.CS2") Rem Example of an optional parameter (requires that you have Rem a document preset named "7x9_book_cover"). Set myDocument = myInDesign.Documents.Add(myInDesign.DocumentPresets.Item("7x9_book_cover")) Set myOval = myDocument.Pages.Item(1).Ovals.Add myOval.GeometricBounds = Array("6p", "6p", "18p", "18p") Set myRectangle = myDocument.Pages.Item(1).Rectangles.Add myRectangle.StrokeWeight = 4 Rem Example of a required parameter. Set myGroup = myDocument.Pages.Item(1).Groups.Add(Array(myOval, myRectangle)) JavaScript //Example of an optional parameter (requires that you have //a document preset named "7x9_book_cover"). var myDocument = app.documents.add(app.documentPresets.item("7x9_book_cover")) //Example of setting object properties as you create the object. var myOval = myDocument.pages.item(0).ovals.add( {geometricBounds:["6p", "6p", "18p", "18p"]}); var myRectangle = myDocument.pages.item(0).rectangles.add( {strokeWeight:4}); //Example of a required parameter. var myGroup = myDocument.pages.item(0).groups.add([myOval, myRectangle]); Control structures Most scripts do not proceed sequentially from beginning to end-they take different paths depending on decisions, or they repeat commands multiple times. Control structures are the commands to do such things. Conditional statements If you could talk to InDesign, you might say, "If the selected object is a rectangle, then set its stroke weight to 12 points." This is an example of a conditional statement. Conditional statements make decisions-they give your scripts a way to evaluate something (such as the color of the selected object, or the number of pages in the publication, or the date) and then act according to the result. Conditional statements almost always start with if. The following examples check the quantity of currently open publications. If no publications are open, the scripts display a message in a dialog box.

  • 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
Scripting Basics
15
AppleScript
In AppleScript, you can also use the “with properties” to specify object properties as the object is created.
tell application "Adobe InDesign CS2"
--Example of an optional parameter (requires that you have a document preset
--named "7x9_book_cover").
set myDocument to make document with document preset "7x9_book_cover"
tell page 1 of myDocument
--Example of using "with properties" to specify object properties as you create the object.
set myOval to make oval with properties {geometric bounds:{"6p", "6p", "18p", "18p"}}
--Another "with properties" example.
set myRectangle to make rectangle with properties {stroke weight:4}
--Example of a required parameter:
set myGroup to make group with properties {group items:{myOval, myRectangle}}
end tell
end tell
VBScript
Set myInDesign = CreateObject("InDesign.Application.CS2")
Rem Example of an optional parameter (requires that you have
Rem a document preset named "7x9_book_cover").
Set myDocument = myInDesign.Documents.Add(myInDesign.DocumentPresets.Item("7x9_book_cover"))
Set myOval = myDocument.Pages.Item(1).Ovals.Add
myOval.GeometricBounds = Array("6p", "6p", "18p", "18p")
Set myRectangle = myDocument.Pages.Item(1).Rectangles.Add
myRectangle.StrokeWeight = 4
Rem Example of a required parameter.
Set myGroup = myDocument.Pages.Item(1).Groups.Add(Array(myOval, myRectangle))
JavaScript
//Example of an optional parameter (requires that you have
//a document preset named "7x9_book_cover").
var myDocument = app.documents.add(app.documentPresets.item("7x9_book_cover"))
//Example of setting object properties as you create the object.
var myOval = myDocument.pages.item(0).ovals.add( {geometricBounds:["6p", "6p", "18p", "18p"]});
var myRectangle = myDocument.pages.item(0).rectangles.add( {strokeWeight:4});
//Example of a required parameter.
var myGroup = myDocument.pages.item(0).groups.add([myOval, myRectangle]);
Control structures
Most scripts do not proceed sequentially from beginning to end—they take different paths depending on
decisions, or they repeat commands multiple times.
Control structures
are the commands to do such things.
Conditional statements
If you could talk to InDesign, you might say, “If the selected object is a rectangle, then set its stroke weight to
12 points.” This is an example of a
conditional statement
. Conditional statements make decisions—they give
your scripts a way to evaluate something (such as the color of the selected object, or the number of pages in
the publication, or the date) and then act according to the result. Conditional statements almost always start
with
if
.
The following examples check the quantity of currently open publications. If no publications are open, the
scripts display a message in a dialog box.