The Photoshop Object Model

This  diagram shows a conceptual overview of the Photoshop document object model.

PS_DOM.gif

The Photoshop object model is a containment hierarchy, which means that objects in the model are identified partially by the objects that contain them. In Photoshop, the Application object, at the top of the hierarchy, contains a Documents collection, which contains Document objects. A Document object contains collections of key classes, such as ArtLayers, HistoryStates, Layers, Layersets, and so on. Using methods in the DOM classes, you can tell Photoshop documents to add and remove objects, or set or change individual object properties such as color, size, and shape.

Top container classes

Application class

The root of the  Photoshop class hierarchy is the Application class.  To access the singleton Application object in ActionScript use this code:

import com.adobe.csawlib.photoshop.Photoshop;
import com.adobe.photoshop.Application;
var app:com.adobe.photoshop.Application = Photoshop.app;

The properties of the Application object give your script access to global values, such as user preferences (app.preferences and app.preferencesFolder), which a user sets interactively in the Photoshop application by using the Preferences dialog, and system information such as the amount of memory available to the application (app.freeMemory), and installed fonts (app.fonts).

The object also has properties that provide application-specific information and higher-level information about any open documents:

The Application object’s methods allow your script to perform application-wide actions. For example, you can open files with the object's  open() method, undo() and redo() transactions, and quit() the application..

Document class

The Document object is used to make modifications to the document image. By using the Document object you can crop, rotate or flip the canvas, resize the image or canvas, and trim the image. Use the Document object to get the active layer, save the current document, copy and paste within the active document or between different documents.

A Document object provides access to these classes:

Class

Description

DocumentInfo

Stores metadata about a document that describes its content or characteristics.

Selection

Use to specify an area of pixels in the active document (or in a selected layer of the active document) that you want to work with.

HistoryState

A palette object that keeps track of changes made to a document. Each time you apply a change to an image, the new state of that image is added to the palette. These states are accessible from the Document object and can be used to reset the document to a previous state. A history state can also be used to fill a selection.

Layer classes

An ArtLayer is a layer object within a document that allows you to work on one element of an image without disturbing the others. You create a new art layer using the add() method of the artLayers collection of a document.  (The parent class, Layer, is not instantiated.)

Layer objects provide access to classes that represent  the content of the layer, or features of the content. For example:

Class

Description

Channel

Stores pixel information about an image’s color. The color space determines the number of channels available; an RGB image, for example, has four default channels: one for each primary color and one for editing the entire image. You could have the red channel active in order to manipulate just the red pixels in the image, or you could choose to manipulate all the channels at once.

These kinds of channels are related to the document mode and are called component channels. In addition to the component channels, Photoshop lets you to create additional channels: a spot color channel, a masked area channel, and a selected area channel.

Use the methods of a Channel object to create, delete and duplicate channels. You can also retrieve a channel's histogram, change its kind or change the current channel selection.

PathItem, SubPathItem, PathPoint

A PathItem represents information about a drawing object, such as the outline of a shape, or a curved line. A SubPathItem object is contained in a PathItem object, and provides the actual geometry of the shape.  PathPoint objects represent each point in a sub-path.  

TextItem

An art layer that contains text has the property artLayer.kind = LayerKind.TEXT; this type of layer allows you to add type to an image.  The text itself is stored in a TextItem object.

Color objects

Color objects allow you to specify colors in any of a number of different color spaces.

ps_colors.png

The SolidColor object contains the color-model objects, which in turn contain specific color values of the types appropriate for that color space. The RGBColor object, for example, has red, green, and blue properties, which can contain hexadecimal or decimal values in the range 0-255. Once you have set color values in one of the color models in a particular SolidColor object, you cannot reassign it to another color space.

See details and examples in Working with Colors and Paths.

Parameter objects and constants

The Photoshop object model includes classes that are used as types for properties or to provide parameter information to methods. For example:

Constants provide enumerated values for "one of" parameters, and types for certain properties. For example, the types of art layer, stored in the layer object's kind property, must be members of the LayerKind enumeration:

 artLayer.kind = LayerKind.TEXT;

All constants are listed in the API Reference.

 

 

Copyright © 2011 Adobe Systems Incorporated. All rights reserved.