Adobe 27510753 Scripting Guide - Page 31

VBScript, Visual Basic

Page 31 highlights

Adobe InDesign CS2 Scripting Guide Getting Started with InDesign Scripting 23 --Hello World tell application "Adobe InDesign CS2" --Create a new document and assign its --identity to the variable "myDocument" set myDocument to make document tell myDocument --Create a new text frame on the first page. tell page 1 set myTextFrame to make text frame --Change the size of the text frame. set geometric bounds of myTextFrame to {"0p0", "0p0", "18p0", "18p0"} --Enter text in the text frame. set contents of myTextFrame to "Hello World!" end tell end tell end tell 3. Save the script. 4. Run the script (click Run in the Script Editor). InDesign creates a new publication, adds a text frame, and enters text. During this process, the Script Editor might ask where your copy of InDesign is located. In this case, select the application from the list of displayed applications, and the Script Editor will remember where it is the next time you run the script. VBScript To create a VBasic script: 1. Start any text editor (Notepad, for example). 2. Enter the following code. The lines preceded by Rem are comments and are ignored by the scripting system. They're included to describe the operation of the program. As you look through the script, you'll see how we create, then address, each object in turn. You do not need to enter the comments. Rem Hello World Set myInDesign = CreateObject("InDesign.Application.CS2") Rem Create a new document. Set myDocument = myInDesign.Documents.Add Rem Get a reference to the first page. Set myPage = myDocument.Pages.Item(1) Rem Create a text frame. Set myTextFrame = myDocument.TextFrames.Add Rem Specify the size and shape of the text frame. myTextFrame.GeometricBounds = Array("0p0", "0p0", "18p0", "18p0") Rem Enter text in the text frame. myTextFrame.Contents = "Hello World!" 3. Save the file as text only to the Scripts folder in the Presets folder inside your InDesign application folder. Give the file the file extension .vbs. 4. Display the Scripts palette, if it's not already visible. Double-click the script name in the palette to run the script. Visual Basic To create a Visual Basic script (the steps shown are for Visual Basic 6; Visual Basic 5 CCE and Visual Basic.NET users will see slightly different dialog boxes): 1. Start Visual Basic and create a new project. Add the InDesign CS Type Library reference to the project, as shown earlier.

  • 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
Getting Started with InDesign Scripting
23
--Hello World
tell application "Adobe InDesign CS2"
--Create a new document and assign its
--identity to the variable "myDocument"
set myDocument to make document
tell myDocument
--Create a new text frame on the first page.
tell page 1
set myTextFrame to make text frame
--Change the size of the text frame.
set geometric bounds of myTextFrame to {"0p0", "0p0", "18p0", "18p0"}
--Enter text in the text frame.
set contents of myTextFrame to "Hello World!"
end tell
end tell
end tell
3. Save the script.
4.
Run the script (click Run in the Script Editor). InDesign creates a new publication, adds a text frame, and
enters text. During this process, the Script Editor might ask where your copy of InDesign is located. In this
case, select the application from the list of displayed applications, and the Script Editor will remember
where it is the next time you run the script.
VBScript
To create a VBasic script:
1.
Start any text editor (Notepad, for example).
2.
Enter the following code. The lines preceded by
Rem
are comments and are ignored by the scripting sys-
tem. They’re included to describe the operation of the program. As you look through the script, you’ll see
how we create, then address, each object in turn. You do not need to enter the comments.
Rem Hello World
Set myInDesign = CreateObject("InDesign.Application.CS2")
Rem Create a new document.
Set myDocument = myInDesign.Documents.Add
Rem Get a reference to the first page.
Set myPage = myDocument.Pages.Item(1)
Rem Create a text frame.
Set myTextFrame = myDocument.TextFrames.Add
Rem Specify the size and shape of the text frame.
myTextFrame.GeometricBounds = Array("0p0", "0p0", "18p0", "18p0")
Rem Enter text in the text frame.
myTextFrame.Contents = "Hello World!"
3.
Save the file as text only to the Scripts folder in the Presets folder inside your InDesign application folder.
Give the file the file extension
.vbs
.
4.
Display the Scripts palette, if it’s not already visible. Double-click the script name in the palette to run the
script.
Visual Basic
To create a Visual Basic script (the steps shown are for Visual Basic 6; Visual Basic 5 CCE and Visual Basic.NET
users will see slightly different dialog boxes):
1.
Start Visual Basic and create a new project. Add the InDesign CS Type Library reference to the project, as
shown earlier.