EDOBE XDOM TPC Technical Information Page 35

  • Download
  • Add to my manuals
  • Print
  • Page
    / 68
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 34
CHAPTER 4: Scripting with AppleScript Object references 35
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:
X Get the active document.
X Get the width of the active document.
X 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
Page view 34
1 2 ... 30 31 32 33 34 35 36 37 38 39 40 ... 67 68

Comments to this Manuals

No comments