
C
HAPTER
3: Scripting Illustrator
Working with objects
28
VBScript
To refer to a
path
items
object in a document:
Documents(1).PathItems(1)
To refer to a
path
items
object in a layer:
Documents(1).Layers(1).PathItems(1)
For more examples of collection-item containers, see the
document
object Elements table in
Adobe
Illustrator CS4 Scripting Reference: AppleScript
or the Properties table in
Adobe Illustrator CS4 Scripting
Reference: JavaScript
or
Adobe Illustrator CS4 Scripting Reference: VBScript
. A diagram of the Illustrator CS4
object model is in
“The Illustrator Scripting Object Model” on page 17
.
Selected objects
Sometimes, you want to write scripts that act on the currently selected object or objects. For example, you
might want to apply formatting to selected text or change a selected path’s shape.
Selecting text
To select text, use the
select
command or method of the
text
range
object.
Selecting art items
You can select an art object (like graph items, mesh items, raster items, and symbol items) by setting its
selected
property to
true
. (In AppleScript,
selected
is a property of the
page
items
object.)
Referring to selected art items
To refer to all currently selected objects in a document, use the
document
object’s
selection
property. To
work with the objects in the selection array, you must determine their type, so you will know which
properties and methods or commands you can use with them. In JavaScript and VBScript, each artwork
object type has a read-only
typename
property that you can use to determine the object’s type. In
AppleScript, use the
class
property.
Notes on renaming objects stored in the application’s panels
Several objects can be renamed; that is, their
name
property is writeable. The following types of objects can
be sorted alphabetically in the corresponding Illustrator panel. If a script modifies the name of such an
object, references to that object by index can become invalid.
Brush
Gradient
Graphic Style
Pattern
Swatch
Symbol
Variable