Layer

A layer object.
 
Shapes

Settings

Creating Shapes

Arrangement

Parent Document

addPathShape:

returns PathShape; input Path

Creates and returns a new path shape, adding it to the layer.
 

Example: create a triangle path shape

var doc = [app activeDocument]
var path = [doc addPath]

[path addMoveTo:CGPointMake(25, 150)]
[path addLineTo:CGPointMake(75, 50)]
[path addLineTo:CGPointMake(125, 150)]
[path addClose]

[[doc activeLayer] addPathShape:path]

addTextShape:

returns TextShape; input NSAttributedString

Creates and returns a new text shape, adding it to the layer.
 

Example: create a text shape styled with a 24pt system bold font

var layer = [[app activeDocument] activeLayer]
var font = [NSFont boldSystemFontOfSize:24]
var dict = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]
var str = [[NSAttributedString alloc] initWithString:"Hello World!" attributes:dict]

var textShape = [layer addTextShape:str]
textShape.position = CGPointMake(120, 100)
[str release]

blendMode

returns String; settable

Gets / Sets the blend mode of the layer.
 

Example:

var layer = [[app activeDocument] activeLayer]
layer.blendMode = "Multiply"

duplicate

returns Layer

Duplicates this layer and its contents. The new layer becomes the selected and active layer.
 

Example: create a duplicate of the active layer with all shapes offset by 40 pixels horiz and vert

var layer = [[app activeDocument] activeLayer]
var newLayer = [layer duplicate]
var shapes = [newLayer shapes]

for(var i = 0; i < [shapes count]; i++)
    [(shapes[i]) translateX:40 y:40]

groupShapes:

returns Shape Group; input Array

Creates and returns a new Shape Group object containing all of the shapes in the passed-in array. The shapes are moved within the group. The input shapes must be direct descendants of this layer.
 

Example: create a group containing all of the shapes in the active layer

var layer = [[app activeDocument] activeLayer]
var shapes = [layer shapes]
[layer groupShapes:shapes]

hidden

returns Boolean; settable

Gets / Sets the hidden state of the layer.
 

Example: hide the layers in the active document that are not currently selected

var doc = [app activeDocument]
var layers = [doc layers]

for(var i = 0; i < [layers count]; i++)
{
    var layer = layers[i]
    layer.hidden = ![layer selected]
}

locked

returns Boolean; settable

Gets / Sets the locked state of the layer.
 

Example: unlock all of the active document's layers

var doc = [app activeDocument]
var layers = [doc layers]

for(var i = 0; i < [layers count]; i++)
    layers[i].locked = false

moveToIndex:

input Integer

Move the layer to a new z-index in parent Document's layer array.
 

Example: move the active layer to the top of the layers list

var doc = [app activeDocument]
var layer = [doc activeLayer]
var allLayers = [doc layers]
[layer moveToIndex:[allLayers count] - 1]

name

returns String; settable

Gets / Sets the name of the layer.
 

Example: set the name of the active layer

var layer = [[app activeDocument] activeLayer]
layer.name = "Hello World!"

opacity

returns Float; settable

Gets / Sets the opacity of the layer. The opacity value is between 0 and 1.
 

Example: set the active layer's opacity to 65%

var layer = [[app activeDocument] activeLayer]
layer.opacity = 0.65

parent

returns Document

Gets the document object that is the parent of the layer.

remove

Removes the layer from the document.

Note: this function does nothing if there is only a single layer remaining in the parent document.
 

Example: remove all layers in the active document that are not currently selected

var doc = [app activeDocument]
var layers = [doc layers]

for(var i = 0; i < [layers count]; i++)
{
    var layer = layers[i]

    if([layer selected] == false)
        [layer remove]
}

selected

returns Boolean; settable

Gets / Sets the selection state of the layer.

Note: deselecting the last selected layer will select a default layer to be the active layer. A document always maintains at least one active selected layer at a given time.
 

Example: select all of the layers in the active document

var doc = [app activeDocument]
var layers = [doc layers]

for(var i = 0; i < [layers count]; i++)
    layers[i].selected = true

shapes

returns Array

Gets the array of shapes in the layer.
 

Example: rotate each shape in the active layer by 90 degrees

var doc = [app activeDocument]
var shapes = [[doc activeLayer] shapes]

for(var i = 0; i < [shapes count]; i++)
    [(shapes[i]) rotate:90]

Next: Shape