Adobe 23102480 Scripting Guide - Page 23

Setting the Active Object

Page 23 highlights

Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Photoshop CS3 23 JS In JavaScript, you can use the add() method only with the collection name. The add() method is not valid with objects other than collection objects. Similar to VBScript, the JavaScript statement to create a document is: documents.add() and not: document.add() Note: You can include an Application object reference if you wish. The following statement is equivalent to the previous sample: app.documents.add() To add an ArtLayer object, you must reference the Document object that contains the layer, and use the add() method for the ArtLayers collection, using the artLayers property of Document. documents[0].artLayers.add() As with VBScript, the add() method is associated with the JavaScript Documents object but not with the Document object. Similarly, the ArtLayer object does not have an add() method; the ArtLayers object does. Note: The Layers collection object does not include an add() method. For more information, look up the Layers object in the Adobe Photoshop CS3 JavaScript Scripting Reference. Setting the Active Object To work on a an object in the Photoshop CS3 application, you must make the object the front-most, or active object. For example, to work in a layer, you must first bring the layer to the front. In scripting, the same rule applies. If your script creates two or more documents, the commands and methods in your script are executed on the active document. Therefore, to ensure that your commands are acting on the correct document, it is good programming practice to designate the active document before executing any commands or methods in the script. To set an active object, do the following: ● In AppleScript, you use the current property of the parent object. ● In VBScript, you use the ActiveObject property of the parent object (such as ActiveDocument or ActiveLayer). ● In JavaScript, you use the activeObject property of the parent object (such as activeDocument or activeLayer). Note: The parent object is the object that contains the specified object. For example, the application is the parent of the document; a document is the parent of a layer, selection, or channel. For example, if you look at the Application object in the Adobe Photoshop CS3 JavaScript Scripting Reference, or in the ExtendScript Object Model Viewer, you find one of its properties is activeDocument; if you look at the Document object, you will find activeLayer and activeHistoryState as properties. Similarly, if you look at application in the Adobe Photoshop CS3 AppleScript Scripting Reference, or in thePhotoshop CS3 AppleScript Dictionary, you find it has the property of current, and so on. For sample scripts that set active objects, see the following sections. ● 'Setting the Active Document' on page 24 ● 'Setting the Active Layer' on page 25 ● 'Setting the Active Channels' on page 25

  • 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
23
JS
In JavaScript, you can use the
add()
method only with the collection name. The
add()
method is not valid
with objects other than collection objects.
Similar to VBScript, the JavaScript statement to create a document is:
documents.add()
and
not
:
document.add()
Note:
You can include an
Application
object reference if you wish. The following statement is equivalent
to the previous sample:
app.documents.add()
To add an
ArtLayer
object, you must reference the
Document
object that contains the layer, and use the
add()
method for the
ArtLayers
collection, using the
artLayers
property of
Document
.
documents[0].artLayers.add()
As with VBScript, the
add()
method is associated with the JavaScript
Documents
object but not with the
Document
object. Similarly, the
ArtLayer
object does not have an
add()
method; the
ArtLayers
object
does.
Note:
The
Layers
collection object does not include an
add()
method. For more information, look up the
Layers
object in the
Adobe Photoshop CS3 JavaScript Scripting Reference
.
Setting the Active Object
To work on a an object in the Photoshop CS3 application, you must make the object the front-most, or
active
object
.
For example, to work in a layer, you must first bring the layer to the front.
In scripting, the same rule applies. If your script creates two or more documents, the commands and
methods in your script are executed on the active document. Therefore, to ensure that your commands are
acting on the correct document, it is good programming practice to designate the active document
before executing any commands or methods in the script.
To set an active object, do the following:
In AppleScript, you use the
current
property of the parent object.
In VBScript, you use the
Active
Object
property of the parent object (such as
ActiveDocument
or
ActiveLayer
).
In JavaScript, you use the
active
Object
property of the parent object (such as
activeDocument
or
activeLayer
).
Note:
The parent object is the object that contains the specified object. For example, the application is the
parent of the document; a document is the parent of a layer, selection, or channel.
For example, if you look at the
Application
object in the
Adobe Photoshop CS3 JavaScript Scripting
Reference
, or in the ExtendScript Object Model Viewer, you find one of its properties is
activeDocument
; if you look at the
Document
object, you will find
activeLayer
and
activeHistoryState
as properties. Similarly, if you look at
application
in the
Adobe Photoshop
CS3 AppleScript Scripting Reference
, or in thePhotoshop CS3 AppleScript Dictionary, you find it has
the property of
current
, and so on.
For sample scripts that set active objects, see the following sections.
‘Setting the Active Document’ on page 24
‘Setting the Active Layer’ on page 25
‘Setting the Active Channels’ on page 25