Shape
A shape object. This is the abstract base class for (link: plugins/api/pathshape text: **PathShape**), (link: plugins/api/textshape text: **TextShape**), and (link: plugins/api/shapegroup text: **ShapeGroup**) objects. _Settings_ - (link: plugins/api/shape#name text: **name**) - (link: plugins/api/shape#locked text: **locked**) - (link: plugins/api/shape#hidden text: **hidden**) - (link: plugins/api/shape#opacity text: **opacity**) - (link: plugins/api/shape#blendMode text: **blendMode**) - (link: plugins/api/shape#selected text: **selected**) _Position / Bounds_ - (link: plugins/api/shape#position text: **position**) - (link: plugins/api/shape#bounds text: **bounds**) - (link: plugins/api/shape#visibleBounds text: **visibleBounds**) _Applying Transforms_ - (link: plugins/api/shape#rotate text: **rotate:**) - (link: plugins/api/shape#rotateorigin text: **rotate: origin:**) - (link: plugins/api/shape#scaleXy text: **scaleX: y:**) - (link: plugins/api/shape#scaleXyorigin text: **scaleX: y: origin:**) - (link: plugins/api/shape#shearXy text: **shearX: y:**) - (link: plugins/api/shape#shearXyorigin text: **shearX: y: origin:**) - (link: plugins/api/shape#translateXy text: **translateX: y:**) _Styling_ - (link: plugins/api/shape#appearance text: **appearance**) - (link: plugins/api/shape#stroke text: **stroke**) - (link: plugins/api/shape#fill text: **fill**) _Arrangement_ - (link: plugins/api/shape#moveToParent text: **moveToParent:**) - (link: plugins/api/shape#moveToIndex text: **moveToIndex:**) - (link: plugins/api/shape#duplicate text: **duplicate**) - (link: plugins/api/shape#remove text: **remove**) _Parent Layer or Group_ - (link: plugins/api/shape#parent text: **parent**) ## appearance ### _returns (link: plugins/api/appearance text: **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 (link: plugins/api/shape text: **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 (link: plugins/api/appearance#fill text: **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 (link: plugins/api/layer text: **Layer**) or (link: plugins/api/shapegroup text: **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 (link: plugins/api/layer text: **Layer**) or (link: plugins/api/shapegroup text: **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 (link: plugins/api/appearance#stroke text: **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