- Viewing Photoshop CS2 objects, commands, and methods
- Creating new objects in a script
- Setting the active object
- Opening a document
- Saving a document
- Setting application preferences
- Suppressing dialog boxes
- Working with the Adobe Photoshop CS2 Object Model
- Working with color objects
- Working with filters
- Understanding clipboard interaction
- Working with units
- Sample workflow automation JavaScripts
- Advanced scripting
Creating new objects in a script
To create a new document in the Adobe Photoshop CS2 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 add() method.
As you can see in the Adobe Photoshop CS2 Object Model, the Document object contains all other objects except the Application object. Therefore, you must reference the Document object when adding objects other than Document objects to your script.
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.
The JavaScript statement to create a document is:
documents.add()
and not:
document.add()
To add an ArtLayer object, you must reference the Document object that will contain the layer.
documents(0).artLayers.add()
The add() method is associated with the JavaScript Documents object but not with the Document object (see Part 2 of this book).
Similarly, the ArtLayer object does not have an add() method; the ArtLayers object does.