Selection

The selection object represents a Document's collection of currently selected shapes, which can be edited together as a group.
 
Shapes

Position / Size

Applying Transforms

Bounding Box

bounds

returns CGRect

Gets the geometric bounding box of the selection.
 

Example: scales the selection by 150%, anchored at the top left corner of the selection's bounding box

var selection = [[app activeDocument] selection]
selection.transformOrigin = [selection bounds].origin
[selection scaleX:1.5 y:1.5]

boundingBoxRotation

returns Float; settable

Gets / Sets the selection's bounding box rotation in degrees. A selection's bounding box is shown rotated when all of the shapes within the selection have the same rotation applied. This property can be adjusted to change or reset the bounding box rotation.
 

Example: reset the selection's bounding box

var selection = [[app activeDocument] selection]
selection.boundingBoxRotation = 0

position

returns CGPoint; settable

Gets / Sets the position of the selection. The position is the top left corner of the selection's bounding box.
 

Example: move to the selection to the top left corner of the canvas

var selection = [[app activeDocument] selection]
selection.position = CGPointMake(0, 0)

rotate:

input Float

Rotate the selection by the passed-in angle in degrees.
 

Example: rotates the selection 15 degrees

var selection = [[app activeDocument] selection]
[selection rotate:15]

scaleX: y:

input Float; input Float

Scale the selection by the passed-in x and y values. A value of 1 is equal to 100% scale.
 

Example: scale the selection by 50%

var selection = [[app activeDocument] selection]
[selection scaleX:0.5 y:0.5]

shapes

returns Array

Gets the array of shapes in the selection. These are the same shapes as returned by the Document's selectedShapes function.
 

Example: deselects all of the currently selected shapes

var selection = [[app activeDocument] selection]
var shapes = [selection shapes]

for(var i = 0; i < [shapes count]; i++)
    shapes[i].selected = false

shearX: y:

input Float; input Float

Shear the selection by the passed-in x and y values. Each value is given in degrees.
 

Example: shear the selection horizontally by 45 degrees

var selection = [[app activeDocument] selection]
[selection shearX:45 y:0]

size

returns CGSize; settable

Gets / Sets the size of the selection's bounding box. Changing this property will scale the shapes in the selection to fit the new size.
 

Example: double the width and height of the selection

var selection = [[app activeDocument] selection]
var size = [selection size]
selection.size = CGSizeMake(size.width * 2, size.height * 2)

transformOrigin

returns CGPoint; settable

Get / Set the origin point used when applying transforms to the selection. This origin point is user-visible when one transform tools is selected (Rotate, Scale, Shear). The origin point can be set to rotate, scale, or shear the selection relative to a specific point on the canvas.
 

Example: rotate the selection -45 degrees, anchored at the bottom right corner of the selection's bounding box

var selection = [[app activeDocument] selection]
var bounds = [selection bounds]
var x = bounds.origin.x + bounds.size.width
var y = bounds.origin.y + bounds.size.height
selection.transformOrigin = CGPointMake(x, y)
[selection rotate:-45]

translateX: y:

input Float; input Float

Move the selection by the passed-in x and y values.
 

Example: move the selection 20 pixels to the left

var selection = [[app activeDocument] selection]
[selection translateX:-20 y:0]

visibleBounds

returns CGRect

Gets the visible bounding box of the selection. This bounding box is large enough to include the stroke widths and other appearance effects applied to each selected shape.
 

Next: Layer