Setting the active object
To work on a an object in the Adobe Photoshop CS2 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, use the activeObject property of the parent object (such as activeDocument or activeLayer).
For sample scripts that set active objects, see the following sections.
- Setting the active document
- Setting the active layer
- Setting the active channels
Setting the active document
The following example demonstrates how to set the active document.
// Create 2 documents var docRef = app.documents.add( 4, 4) var otherDocRef = app.documents.add (4,6) //make docRef the active document app.activeDocument = docRef //here you would include command statements //that perform actions on the active document. Then, you could //make a different document the active document //use the activeDocument property of the Application object to //bring otherDocRef front-most as the new active document app.activeDocument = otherDocRef
Setting the active layer
The following example demonstrates how to use the current layer (ActiveLayer/activeLayer) property of the Document object to set the active layer.
docRef.activeLayer = docRef.layers["Layer 1"]
Setting the active channels
More than one channel can be active at a time.
Set the active channels to the first and third channel using a channel array:
theChannels = new Array(docRef.channels, docRef.channels) docRef.activeChannels = theChannels
Alternatively, select all component channels by using the componentChannels property of the Document object:
app.activeDocument.activeChannels = activeDocument.componentChannels