Adobe 65010248 Scripting Guide - Page 35

Obtaining objects from documents and layers, Creating new objects, Working with selections

Page 35 highlights

CHAPTER 4: Scripting with AppleScript Object references 35 each consecutive make command. (Choose Event Log at the bottom of the Script Editor window.) Notice that both commands return the same object reference: path item 1 of layer 1 of document 1; therefore, the last line resolves to: set selection of document 1 to {path item 1 of layer 1 of document 1, path item 1 of layer 1 of document 1} A better approach is to reference the objects by name: tell application "Adobe Illustrator" set newDocument to make new document make new rectangle in newDocument with properties {name:"rectangle"} make new star in newDocument with properties {name:"star"} set selection of newDocument to {path item "rectangle" of newDocument, path item "star" of newDocument} end tell This example illustrates the need to uniquely identify objects in AppleScript scripts. We recommend that you assign names or variables to objects you need to access at a later time, as there is no guarantee you are accessing the objects you expect when accessing them by index. Obtaining objects from documents and layers This script references an object as part of a document: -- Get reference for first page item of document 1 tell application "Adobe Illustrator" set pageItemRef to page item 1 of document 1 end tell In the following script, the pageItemRef variable does not necessarily refer to the same object as in the previous script, because this script includes a reference to a layer: -- Get reference for first page item of layer 1 of document 1 tell application "Adobe Illustrator" set pageItemRef to page item 1 of layer 1 of document 1 end tell Creating new objects To create a new object in AppleScript, use the make command. Working with selections When the user makes a selection in a document, the selected objects are stored in the document's selection property. To access all selected objects in the active document: tell application "Adobe Illustrator" set myDoc to current document set selectedObjects to selection of myDoc end tell

  • 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

C
HAPTER
4: Scripting with AppleScript
Object references
35
each consecutive
make
command. (Choose Event Log at the bottom of the Script Editor window.) Notice
that both commands return the same object reference:
path
item
1
of
layer
1
of
document
1
; therefore,
the last line resolves to:
set selection of document 1 to {path item 1 of layer 1 of document 1,
path item 1 of layer 1 of document 1}
A better approach is to reference the objects by name:
tell application "Adobe Illustrator"
set newDocument to make new document
make new rectangle in newDocument with properties {name:"rectangle"}
make new star in newDocument with properties {name:"star"}
set selection of newDocument to
{path item "rectangle" of newDocument,
path item "star" of newDocument}
end tell
This example illustrates the need to uniquely identify objects in AppleScript scripts. We recommend that
you assign names or variables to objects you need to access at a later time, as there is no guarantee you
are accessing the objects you expect when accessing them by index.
Obtaining objects from documents and layers
This script references an object as part of a document:
-- Get reference for first page item of document 1
tell application "Adobe Illustrator"
set pageItemRef to page item 1 of document 1
end tell
In the following script, the
pageItemRef
variable does not necessarily refer to the same object as in the
previous script, because this script includes a reference to a layer:
-- Get reference for first page item of layer 1 of document 1
tell application "Adobe Illustrator"
set pageItemRef to page item 1 of layer 1 of document 1
end tell
Creating new objects
To create a new object in AppleScript, use the
make
command.
Working with selections
When the user makes a selection in a document, the selected objects are stored in the document’s
selection
property. To access all selected objects in the active document:
tell application "Adobe Illustrator"
set myDoc to current document
set selectedObjects to selection of myDoc
end tell