Adobe 23102480 Scripting Guide - Page 21

Creating New Objects in a Script, File > New

Page 21 highlights

Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Photoshop CS3 21 ... end tell Note: Because you include all commands in the tell block, there is no need to reference the Application object throughout the script. VBS In VBScript, do the following to target the application: Dim appRef Set appRef = CreateObject("Photoshop.Application") JS In JavaScript, because you do not need to reference an Application object, all properties and methods of the application are accessible without any qualification. You can reference the application as part of the containment hierarchy or leave it out, whichever makes your scripts easier for you to read. To reference the Application object, use the pre-defined global object app, rather than the class name. The following statements are equivalent: var docRef = app.documents[1] and var docRef=documents[1] Note: Many JavaScript samples throughout this guide do not reference the Application object. Creating New Objects in a Script To create a new document in the Photoshop CS3 application, you select File > New. To create other types of objects within a document, such as a layer, channel, or path, you use the Window menu or choose the New icon on the appropriate palette. This section demonstrates how to accomplish these same tasks in a script. To create an object in a script, you name the type of object you want to create and then use the following command: ● AS: make ● VBS: Add ● JS: add() As you can see in the 'Photoshop CS3 Object Model' on page 9, the Document object contains all other objects except the Application, Notifier, and Preferences objects. Therefore, you must reference the Document object when adding objects other than Document and Notifier objects to your script. (It is not possible to add a new Preferences object.) Note: In VBScript and JavaScript, you use the object's collection name to name the object type. For example, you add a document to the Documents collection; you add an art layer to the art layers collection. See Introduction to Scripting for more information on elements and collections. 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:

  • 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

Photoshop CS3
Adobe Photoshop CS3
Scripting Guide
Scripting Photoshop CS3
21
end tell
Note:
Because you include all commands in the
tell
block, there is no need to reference the
Application
object throughout the script.
VBS
In VBScript, do the following to target the application:
Dim appRef
Set appRef = CreateObject("Photoshop.Application")
JS
In JavaScript, because you do not need to reference an
Application
object, all properties and methods of
the application are accessible without any qualification. You can reference the application as part of the
containment hierarchy or leave it out, whichever makes your scripts easier for you to read.
To reference the
Application
object, use the pre-defined global object
app
, rather than the class name.
The following statements are equivalent:
var docRef = app.documents[1]
and
var docRef=documents[1]
Note:
Many JavaScript samples throughout this guide do not reference the
Application
object.
Creating New Objects in a Script
To create a new document in the Photoshop CS3 application, you select
File > New
. To create other types
of objects within a document, such as a layer, channel, or path, you use the Window menu or choose the
New
icon on the appropriate palette. This section demonstrates how to accomplish these same tasks in a
script.
To create an object in a script, you name the type of object you want to create and then use the following
command:
AS:
make
VBS:
Add
JS:
add()
As you can see in the
‘Photoshop CS3 Object Model’ on page 9
, the
Document
object contains all other
objects except the
Application
,
Notifier
, and
Preferences
objects. Therefore, you must reference the
Document
object when adding objects other than
Document
and
Notifier
objects to your script. (It is not
possible to add a new Preferences object.)
Note:
In VBScript and JavaScript, you use the object’s collection name to name the object type. For
example, you add a document to the
Documents
collection; you add an art layer to the
art layers
collection. See
Introduction to Scripting
for more information on elements and collections.
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: