Adding Features To "Hello World; Object References - Adobe 65010248 - Illustrator CS4 - PC Manual

Scripting guide
Hide thumbs Also See for 65010248 - Illustrator CS4 - PC:
Table of Contents

Advertisement

C
4: Scripting with AppleScript
HAPTER

Adding features to "Hello World"

Next, we create a new script that makes changes to the Illustrator document you created with your first
script. Our second script demonstrates how to:
Get the active document.
Get the width of the active document.
Resize the text frame to match the document's width.
If you already closed the Illustrator document, run your first script again to create a new document.
Follow these steps:
1. In Script Editor, choose File > New to create a new script.
2. Enter the following code:
tell application "Adobe Illustrator"
-- current document is always the active document
set docRef to the current document
set docWidth to the width of docRef
-- resize the text frame to match the page width
set width of text frame 1 of docRef to docWidth
-- alternatively, one can reference the item directly, as follows:
set width of text frame 1 of current document to docWidth
end tell
3. Run the script.

Object references

In AppleScript, Illustrator returns object references by index position or name. For example, this is a
reference to the first path in layer 2:
path item 1 of layer 2 of document 1
An object's index position may change when other objects are created or deleted. For example, when a
new path item is created on
This new object displaces the original path item, forcing the original to index position 2; therefore, any
references made to
applying index numbers assures that lowest index number refers to the object that was worked on most
recently.
Consider the following sample script:
-- Make 2 new objects and try to select both
tell application "Adobe Illustrator"
set newDocument to make new document
set rectPath to make new rectangle in newDocument
set starPath to make new star in newDocument
set selection of newDocument to {rectPath, starPath}
end tell
This script does not select both the rectangle and the star, as intended; instead, it selects only the star. Try
running the script with the Event Log window open, to observe the references returned from Illustrator for
, the new path item becomes
layer 2
path item 1 of layer 2 of document 1
path item 1 of layer 2 of document 1
refer to the new object. This method of
Object references 34
.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Illustrator cs4

Table of Contents