Publishers of technology books, eBooks, and videos for creative people

Home > Articles

  • Print
  • + Share This
This chapter is from the book

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:


and not:


To add an ArtLayer object, you must reference the Document object that will contain the layer.


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.

  • + Share This
  • 🔖 Save To Your Account