Skip to content

Layers

app.activeDocument.layers

The collection of layers in the document.


app.activeDocument.layers.length

The number of objects in the collection.

Number; read-only.


app.activeDocument.layers.parent

The parent of this object.

Object; read-only.


app.activeDocument.layers.typename

The class name of the referenced object.

String; read-only.


app.activeDocument.layers.add()

Creates a new layer in the document.

Layer


app.activeDocument.layers.getByName(name)

Gets the first element in the collection with the specified name.

ParameterTypeDescription
nameStringName of element to get

Layer


app.activeDocument.layers.index(itemKey)

Gets an element from the collection.

ParameterTypeDescription
itemKeyString, NumberString or number key

Layer


app.activeDocument.layers.removeAll()

Deletes all elements in this collection.

Nothing.


// Deletes all layers whose name begins with "Temp" in all open documents
var layersDeleted = 0;
for (var i = 0; i < app.documents.length; i++) {
var targetDocument = app.documents[i];
var layerCount = targetDocument.layers.length;
// Loop through layers from the back, to preserve index
// of remaining layers when we remove one
for (var ii = layerCount - 1; ii >= 0; ii--) {
var targetLayer = targetDocument.layers[ii];
var layerName = new String(targetLayer.name);
if (layerName.indexOf("Temp") == 0) {
targetDocument.layers[ii].remove();
layersDeleted++;
}
}
}