Adobe 65014293 Scripting Guide - Page 24

Adobe Photoshop CS4 AppleScript Scripting Reference, Adobe Photoshop

Page 24 highlights

CHAPTER 3: Scripting Photoshop Creating New Objects in a Script 24 AS The following statement creates a Document object in an AppleScript. make new document You can also use the set command to create a variable to hold a reference to a new document. In the following example, the variable named docRef holds a reference to the new document: set docRef to make new document To create an object other than a document, you must reference the Document object that contains the object. The following sample creates an art layer in the document contained in the variable named docRef. make new art layer in docRef NOTE: When you create object in AppleScript, you actually add the object to an element the same way you add a VBScript or JavaScript object to a collection. However, in AppleScript, the element name is implied in the make or set statement. For example, the statement: make new document actually means: make new document in the documents element Do the following to find out more about creating objects in an AppleScript: ➤ Look up the make and set commands in the Adobe Photoshop CS4 AppleScript Scripting Reference or in the Photoshop AppleScript Dictionary. See "Viewing Photoshop's AppleScript dictionary" on page 21. ➤ To find out which commands can be used with an object, look up the object in the Adobe Photoshop CS4 AppleScript Scripting Reference. If an object has valid commands, there will be a "Valid Commands" list at the end of the object description. VBS In VBScript, you can use the Add method only with the collection name. The Add method is not valid with objects other than collection objects. Also, in VBScript, you must reference the Application object when creating when creating, or referring to, an object in your script. For example, to create a document in a VBScript script, you cannot use the object name, as in the following sample, which creates a Document object: appRef.Document.Add() You must use the collection name, which is a plural form of the object name, as follows: appRef.Documents.Add() NOTE: In this sample statement, the Application object is referenced via a variable named appRef. See "Targeting and Referencing the Application Object" on page 22 for more information. To add an ArtLayer object, you must reference both the Application and Document objects that will contain the art layer. The following sample references the Application object using the variable appRef and the Document object using the document's index rather than the documents name. appRef.Documents(1).ArtLayers.Add() NOTE: In Photoshop, VBScript collections index from 1 rather than 0. That is to say, the first document created has index 1, rather than index 0.

  • 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
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87

C
HAPTER
3: Scripting Photoshop
Creating New Objects in a Script
24
AS
The following statement creates a
Document
object in an AppleScript.
make new document
You can also use the
set
command to create a variable to hold a reference to a new document. In the
following example, the variable named
docRef
holds a reference to the new document:
set docRef to make new document
To create an object other than a document, you must reference the
Document
object that contains the
object. The following sample creates an art layer in the document contained in the variable named
docRef
.
make new art layer in docRef
N
OTE
:
When you create object in AppleScript, you actually add the object to an element the same way you
add a VBScript or JavaScript object to a collection. However, in AppleScript, the element name is implied in
the
make
or
set
statement. For example, the statement:
make new document
actually means:
make new document in the documents element
Do the following to find out more about creating objects in an AppleScript:
Look up the
make
and
set
commands in the
Adobe Photoshop CS4 AppleScript Scripting Reference
or in
the Photoshop AppleScript Dictionary. See
“Viewing Photoshop’s AppleScript dictionary” on page 21
.
To find out which commands can be used with an object, look up the object in the
Adobe Photoshop
CS4 AppleScript Scripting Reference
. If an object has valid commands, there will be a “Valid Commands”
list at the end of the object description.
VBS
In VBScript, you can use the
Add
method
only
with the collection name. The
Add
method is not valid with
objects other than collection objects. Also, in VBScript, you must reference the
Application
object when
creating when creating, or referring to, an object in your script.
For example, to create a document in a VBScript script, you
cannot
use the object name, as in the following
sample, which creates a
Document
object:
appRef.Document.Add()
You must use the collection name, which is a plural form of the object name, as follows:
appRef.Documents.Add()
N
OTE
:
In this sample statement, the
Application
object is referenced via a variable named
appRef
. See
“Targeting and Referencing the Application Object” on page 22
for more information.
To add an
ArtLayer
object, you must reference both the
Application
and
Document
objects that will
contain the art layer. The following sample references the
Application
object using the variable
appRef
and the
Document
object using the document’s index rather than the documents name.
appRef.Documents(1).ArtLayers.Add()
N
OTE
:
In Photoshop, VBScript collections index from 1 rather than 0. That is to say, the first document
created has index 1, rather than index 0.