Layers
Layers
Section titled “Layers”app.activeDocument.layers
Description
Section titled “Description”The collection of layers in the document.
Properties
Section titled “Properties”Layers.length
Section titled “Layers.length”app.activeDocument.layers.length
Description
Section titled “Description”The number of objects in the collection.
Number; read-only.
Layers.parent
Section titled “Layers.parent”app.activeDocument.layers.parent
Description
Section titled “Description”The parent of this object.
Object; read-only.
Layers.typename
Section titled “Layers.typename”app.activeDocument.layers.typename
Description
Section titled “Description”The class name of the referenced object.
String; read-only.
Methods
Section titled “Methods”Layers.add()
Section titled “Layers.add()”app.activeDocument.layers.add()
Description
Section titled “Description”Creates a new layer in the document.
Returns
Section titled “Returns”Layers.getByName()
Section titled “Layers.getByName()”app.activeDocument.layers.getByName(name)
Description
Section titled “Description”Gets the first element in the collection with the specified name.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
name | String | Name of element to get |
Returns
Section titled “Returns”Layers.index()
Section titled “Layers.index()”app.activeDocument.layers.index(itemKey)
Description
Section titled “Description”Gets an element from the collection.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
itemKey | String, Number | String or number key |
Returns
Section titled “Returns”Layers.removeAll()
Section titled “Layers.removeAll()”app.activeDocument.layers.removeAll()
Description
Section titled “Description”Deletes all elements in this collection.
Returns
Section titled “Returns”Nothing.
Example
Section titled “Example”Finding and deleting layers
Section titled “Finding and deleting layers”// 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++; } }}