Adobe 65010248 Scripting Guide - Page 48

Scripting with VBScript, For more information, Your first Illustrator script

Page 48 highlights

6 Scripting with VBScript This chapter uses script examples and explanations to help you to become familiar with Illustrator scripting using VBScript. For more information Several extended sample scripts are in the /Scripting/Sample Scripts folder in your Illustrator CS4 installation directory. For information about individual classes, objects, properties, methods, and parameters, as well as script samples that demonstrate how to use many of these items, see Adobe Illustrator CS Scripting Reference: VBScript, in the /Scripting/Documentation folder in your Illustrator CS4 installation directory. You also can view the Illustrator CS4 type library from most VBScript editors or any Microsoft Office application; see "Viewing the VBScript object model" on page 9. If you do not understand the concepts and terms used in this chapter, read Adobe Introduction to Scripting. Your first Illustrator script The traditional first project in any programming language is displaying the message "Hello World!" Follow these steps: 1. Start any text editor (for example, Notepad). 2. Type the following code: Rem Hello World Set appRef = CreateObject("Illustrator.Application") Rem Create a new document and assign it to a variable Set documentRef = appRef.Documents.Add Rem Create a new text frame item and assign it to a variable Set sampleText = documentRef.TextFrames.Add Rem Set the contents and position of the TextFrame sampleText.Position = Array(200, 200) sampleText.Contents = "Hello World!" 3. Save the file as text-only in a folder of your choice, using the file extension .vbs. 4. To test the script, do one of the following: ➣ Double-click the file. ➣ Start Illustrator, choose File > Scripts > Other Scripts, and navigate to and run your script file. TIP: To add the script to the Illustrator Scripts menu (File > Scripts), save the script in the Scripts folder. The script will appear on the menu the next time you start Illustrator. For details, see "Installing scripts in the Scripts menu" on page 10. In general, when you launch a VBScript script from the Scripts menu, any msgBox dialogs will not display correctly. 48

  • 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

48
6
Scripting with VBScript
This chapter uses script examples and explanations to help you to become familiar with Illustrator
scripting using VBScript.
For more information
Several extended sample scripts are in the
/Scripting/Sample
Scripts
folder in your Illustrator CS4
installation directory.
For information about individual classes, objects, properties, methods, and parameters, as well as script
samples that demonstrate how to use many of these items, see
Adobe Illustrator CS Scripting Reference:
VBScript
, in the
/Scripting/Documentation
folder in your Illustrator CS4 installation directory. You also
can view the Illustrator CS4 type library from most VBScript editors or any Microsoft Office application; see
Viewing the VBScript object model
” on page 9
.
If you do not understand the concepts and terms used in this chapter, read
Adobe Introduction to Scripting
.
Your first Illustrator script
The traditional first project in any programming language is displaying the message “Hello World!” Follow
these steps:
1.
Start any text editor (for example, Notepad).
2.
Type the following code:
Rem Hello World
Set appRef = CreateObject("Illustrator.Application")
Rem Create a new document and assign it to a variable
Set documentRef = appRef.Documents.Add
Rem Create a new text frame item and assign it to a variable
Set sampleText = documentRef.TextFrames.Add
Rem Set the contents and position of the TextFrame
sampleText.Position = Array(200, 200)
sampleText.Contents = "Hello World!"
3.
Save the file as text-only in a folder of your choice, using the file extension
.vbs
.
4.
To test the script, do one of the following:
Double-click the file.
Start Illustrator, choose File > Scripts > Other Scripts, and navigate to and run your script file.
T
IP
:
To add the script to the Illustrator Scripts menu (File > Scripts), save the script in the Scripts folder. The
script will appear on the menu the next time you start Illustrator. For details, see
Installing scripts in the
Scripts menu
” on page 10
. In general, when you launch a VBScript script from the Scripts menu, any
msgBox
dialogs will not display correctly.