Shape
A shape object. This is the abstract base class for PathShape, TextShape, and ShapeGroup objects.
Settings
Position / Bounds
Applying Transforms
Styling
Arrangement
Parent Layer or Group
appearance
returns Appearance
Gets the appearance object of the shape. The appearance object contains the stack of appearance items - fills, strokes, shadows, etc. - applied to the shape.
Example: enables and modifies the drop shadow of the frontmost selected shape
var doc = [app activeDocument]
var shape = [[doc selectedShapes] lastObject]
if(shape)
{
var items = [[shape appearance] items]
for(var i = 0; i < [items count]; i++)
{
var item = items[i]
if([item type] == "dropShadow")
{
item.enabled = true
item.offset = CGSizeMake(2, 2)
item.blur = 3
break
}
}
}
blendMode
returns String; settable
Gets / Sets the blend mode of the shape.
Example: set the blend mode of the selected shapes
var doc = [app activeDocument]
var shapes = [doc selectedShapes]
for(var i = 0; i < [shapes count]; i++)
{
shape = shapes[i]
shape.blendMode = "Multiply"
}
bounds
returns CGRect
Gets the geometric bounding box of the shape.
Example: distribute the selected shapes horizontally using each shape's bounds
var doc = [app activeDocument]
var shapes = [doc selectedShapes]
var x
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
var bounds = [shape bounds]
if(i == 0)
x = bounds.origin.x
else
shape.position = CGPointMake(x, bounds.origin.y)
x += bounds.size.width
}
duplicate
returns Shape
Duplicates this shape and adds it to same parent layer or group.
Example: create a duplicate of the frontmost selected shape, offset by 40 pixels horiz and vert
var doc = [app activeDocument]
var shape = [[doc selectedShapes] lastObject]
var newShape = [shape duplicate]
[newShape translateX:40 y:40]
fill
returns AppearanceFill
Gets the fill appearance item of the shape.
Example: set the fill color of the frontmost selected shape
var doc = [app activeDocument]
var shape = [[doc selectedShapes] lastObject]
if(shape)
{
var color = [doc addColorWithRed:255 green:128 blue:0 alpha:1]
[shape fill].color = color
}
hidden
returns Boolean; settable
Gets / Sets the hidden state of the shape.
Example: toggle the visibility of all of the shapes in the active layer
var doc = [app activeDocument]
var shapes = [[doc activeLayer] shapes]
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
shape.hidden = ![shape hidden]
}
locked
returns Boolean; settable
Gets / Sets the locked state of the shape.
Example: unlock all of the shapes in the active layer
var doc = [app activeDocument]
var shapes = [[doc activeLayer] shapes]
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
shape.locked = false
}
moveToIndex:
input Integer
Move the shape to a new z-index in parent layer's or parent group's shapes array.
Example: move each of the selected shapes to the top of their parent's shapes array
var doc = [app activeDocument]
var shapes = [doc selectedShapes]
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
var parent = [shape parent]
var siblings = [parent shapes]
[shape moveToIndex:[siblings count] - 1]
}
moveToParent:
_input Layer or ShapeGroup
Move the shape to a different parent layer or group. The shape is added to the target parent's shapes 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 shape.
Example: set the names of the selected shapes
var shapes = [[app activeDocument] selectedShapes]
for(var i = 0; i < [shapes count]; i++)
shapes[i].name = "Shape " + (i + 1)
opacity
returns Float; settable
Gets / Sets the opacity of the shape. The opacity value is between 0 and 1.
Example: set the frontmost selected shape's opacity to 50%
var doc = [app activeDocument]
var shape = [[doc selectedShapes] lastObject]
if(shape)
shape.opacity = 0.50
parent
returns Layer or ShapeGroup
Gets the parent object of the shape. Shapes can be child objects of layers or groups.
position
returns CGPoint; settable
Gets / Sets the position of the shape. The position is the top left corner of the shape's bounding box.
Example: move the frontmost selected shape to the top left corner of the canvas
var shape = [[[app activeDocument] selectedShapes] lastObject]
shape.position = CGPointMake(0, 0)
remove
Removes the shape from the document by removing it from its parent layer or group.
Example: remove all shapes in the active layer that are not currently selected
var layer = [[app activeDocument] activeLayer]
var shapes = [layer shapes]
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
if([shape selected] == false)
[shape remove]
}
rotate:
input Float
Rotate the shape by the passed-in angle in degrees.
Example: rotates each selected shape by 15 degrees
var shapes = [[app activeDocument] selectedShapes]
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
[shape rotate:15]
}
rotate: origin:
input Float; input CGPoint
Rotate the shape by the passed-in angle in degrees, relative to the passed-in origin.
Example: rotates each selected shape by 15 degrees, around the canvas origin
var shapes = [[app activeDocument] selectedShapes]
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
[shape rotate:15 origin: CGPointMake(0, 0)]
}
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 each selected shape by 150%
var shapes = [[app activeDocument] selectedShapes]
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
[shape scaleX:1.5 y:1.5]
}
scaleX: y: origin:
input Float; input Float; input CGPoint
Scale the selection by the passed-in x and y values. A value of 1 is equal to 100% scale.
Example: scale each selected shape by 150%, anchored at the bottom right corner of its bounding box
var shapes = [[app activeDocument] selectedShapes]
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
var bounds = [shape bounds]
var pnt = CGPointMake(CGRectGetMaxX(bounds), CGRectGetMaxY(bounds))
[shape scaleX:1.5 y:1.5 origin:pnt]
}
selected
returns Boolean; settable
Gets / Sets the selection state of the shape.
Example: invert the shape selection in the active layer
var layer = [[app activeDocument] activeLayer]
var shapes = [layer shapes]
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
shape.selected = ![shape selected]
}
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 each of the selected shapes horizontally by 45 degrees
var shapes = [[app activeDocument] selectedShapes]
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
[shape shearX:45 y:0]
}
shearX: y: origin:
input Float; input Float; input CGPoint
Shear the selection by the passed-in x and y values. Each value is given in degrees.
Example: shear each of the selected shapes horizontally by 45 degrees, anchored at their bounding box origins
var shapes = [[app activeDocument] selectedShapes]
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
[shape shearX:45 y:0 origin:[shape bounds].origin]
}
stroke
returns AppearanceStroke
Gets the stroke appearance item of the shape.
Example: set the stroke width of the frontmost selected shape to 10pt
var doc = [app activeDocument]
var shape = [[doc selectedShapes] lastObject]
if(shape)
{
var color = [doc addColorWithRed:255 green:128 blue:0 alpha:1]
[shape stroke].width = 10
}
translateX: y:
input Float; input Float
Move the selection by the passed-in x and y values.
Example: offsets each shape in the selection by its bounding box width
var shapes = [[app activeDocument] selectedShapes]
for(var i = 0; i < [shapes count]; i++)
{
var shape = shapes[i]
var bounds = [shape bounds]
[shape translateX:bounds.size.width y:0]
}
visibleBounds
returns CGRect
Gets the visible bounding box of the shape. This bounding box is large enough to include the stroke widths and other appearance effects applied to the shape.
Next: ShapeGroup
