Adobe 27510753 Scripting Guide - Page 152

Creating a new document, Opening a document, Document.Add, ShowingWindow

Page 152 highlights

144 Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide Basic document management In almost all situations, your script needs to either open or create a document, save it, and then close it. Creating a new document If a document does not already exist, you must create one. To create a document: Rem MakeDocument.vbs Rem An InDesign CS2 VBScript Rem Creates a new document. Set myInDesign = CreateObject("InDesign.Application.CS2") Set myDocument = myInDesign.Documents.Add The Document.Add method can take two optional parameters, as shown in the following script: Rem MakeDocumentWithParameters.vbs Rem An InDesign CS2 VBScript Rem Creates a new document. Rem The first parameter (ShowingWindow) controls the visibility of the document. Rem Hidden documents are not minimized, and will not appear until you Rem create a new window. Rem The second parameter (DocumentPreset) specifies the document preset to use. Rem The following line assumes that you have defined a document Rem preset named "Flyer". Set myInDesign = CreateObject("InDesign.Application.CS2") Set myDocument = myInDesign.Documents.Add(True, myInDesign.DocumentPresets.Item("Flyer")) Rem If you set the ShowingWindow parameter to False, you can Rem show the document by creating a new window. Rem Set myLayoutWindow = myDocument.Windows.Add Opening a document The following example script shows how to open an existing document: Rem OpenDocument.vbs Rem An InDesign CS2 VBScript Rem Opens an existing document. You'll have to fill in your own file path. Set myInDesign = CreateObject("InDesign.Application.CS2") Set myDocument = myInDesign.Open("c:\myTestDocument.indd") You can choose to prevent the document from displaying (hide it) by setting the ShowingWindow parameter of the Open method to false (the default is true). You might want to do this to improve performance of a script. To show a hidden document, create a new window, as shown in the following script: Rem OpenDocumentInBackground.vbs Rem An InDesign CS2 VBScript Rem Opens an existing document in the background, then shows the document. Rem Youíll have to fill in your own file path. Set myInDesign = CreateObject("InDesign.Application.CS2") Set myDocument = myInDesign.Open("c:\myTestDocument.indd", False) Rem At this point, you can do things with the document without showing the Rem document window. In some cases, scripts will run faster when the document Rem window is not visible. Rem When you want to show the hidden document, create a new window. Set myLayoutWindow = myDocument.Windows.Add

  • 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

144
Working with Documents in VBScript
Adobe InDesign CS2 Scripting Guide
Basic document management
In almost all situations, your script needs to either open or create a document, save it, and then close it.
Creating a new document
If a document does not already exist, you must create one. To create a document:
Rem MakeDocument.vbs
Rem An InDesign CS2 VBScript
Rem Creates a new document.
Set myInDesign = CreateObject("InDesign.Application.CS2")
Set myDocument = myInDesign.Documents.Add
The
Document.Add
method can take two optional parameters, as shown in the following script:
Rem MakeDocumentWithParameters.vbs
Rem An InDesign CS2 VBScript
Rem Creates a new document.
Rem The first parameter (ShowingWindow) controls the visibility of the document.
Rem Hidden documents are not minimized, and will not appear until you
Rem create a new window.
Rem The second parameter (DocumentPreset) specifies the document preset to use.
Rem The following line assumes that you have defined a document
Rem preset named "Flyer".
Set myInDesign = CreateObject("InDesign.Application.CS2")
Set myDocument = myInDesign.Documents.Add(True, myInDesign.DocumentPresets.Item("Flyer"))
Rem If you set the ShowingWindow parameter to False, you can
Rem show the document by creating a new window.
Rem Set myLayoutWindow = myDocument.Windows.Add
Opening a document
The following example script shows how to open an existing document:
Rem OpenDocument.vbs
Rem An InDesign CS2 VBScript
Rem Opens an existing document. You’ll have to fill in your own file path.
Set myInDesign = CreateObject("InDesign.Application.CS2")
Set myDocument = myInDesign.Open("c:\myTestDocument.indd")
You can choose to prevent the document from displaying (hide it) by setting the
ShowingWindow
parameter
of the
Open
method to false (the default is true). You might want to do this to improve performance of a
script. To show a hidden document, create a new window, as shown in the following script:
Rem OpenDocumentInBackground.vbs
Rem An InDesign CS2 VBScript
Rem Opens an existing document in the background, then shows the document.
Rem Youíll have to fill in your own file path.
Set myInDesign = CreateObject("InDesign.Application.CS2")
Set myDocument = myInDesign.Open("c:\myTestDocument.indd", False)
Rem At this point, you can do things with the document without showing the
Rem document window. In some cases, scripts will run faster when the document
Rem window is not visible.
Rem When you want to show the hidden document, create a new window.
Set myLayoutWindow = myDocument.Windows.Add