
Adobe Photoshop CS3
JavaScript Scripting Reference
JavaScript Object Reference 127
Layers
The collection of layer objects, including
ArtLayer
and
LayerSet
objects, in the document.
Note:
Because the
Layers
object is a property of the
Document
object (as well as several other objects),
you use the property name,
layers
, rather than the class name,
Layers
, in your code. The following
example uses the
length
property to count the number of
layer
objects in the active document,
then displays the number on the screen:
var layerNum = app.activeDocument.layers.length
alert(layerNum)
The following example uses an upper case
L
, which is incorrect:
var layerNum = app.activeDocument.Layers.length
alert(layerNum)
Properties
Methods
Property
Value Type
What it is
length
number (long)
Read-only. The number of elements in the
layers
collection.
parent
object (document
or layerSet)
Read-only. The
layers
object's container.
typename
string
Read-only. The class name of the referenced
layers
object.
Method
Parameter Type
Returns
What it does
index
(itemKey)
number
object(Layer)
Gets an element from the collection.
getByName
(name)
string
Layer
Gets the first element in the
layers
collection with the provided name.
removeAll
()
Removes all layers from the collection.