Adobe 65010248 Scripting Guide - Page 34
Adding features to “Hello World”, Object references
UPC - 883919156484
View all Adobe 65010248 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 34 highlights
CHAPTER 4: Scripting with AppleScript Object references 34 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 layer 2, the new path item becomes path item 1 of layer 2 of document 1. This new object displaces the original path item, forcing the original to index position 2; therefore, any references made to path item 1 of layer 2 of document 1 refer to the new object. This method of 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