
<%-- ~/Projects/acorn8/bin/generate_javascript_api_docs.py --%>
<%-- AUTODOC_START --%>

## Application

Top-level methods available from the global acorn object. Is a subclass of NSApplication from AppKit.

<a id="acorn-alldocuments"></a>

### `acorn.allDocuments()`

Returns an array of all open image documents

Returns: Array An array of Documents

```javascript
 acorn.allDocuments().forEach((doc, index) => {
     // doc is a NSDocument subclass
     // fileURL will be null if the file is not saved yet.
     if (doc.fileURL() != null) {
         print(doc.fileURL().path())
     }
 });
```

<a id="acorn-currentdocument"></a>

### `acorn.currentDocument()`

Grab the frontmost Acorn document.

Returns: Document The current document, or null if there are no Acorn documents.

```javascript
var doc = acorn.currentDocument();
if (doc) {
    print(doc.canvasSize().width + "x" + doc.canvasSize().height);
}
```

<a id="acorn-setpreference_forkey"></a>

### `acorn.setPreference_forKey(value, key)`

Sets a preference for given name. (`defaults read com.flyingmeat.Acorn8` to find out what you’ve already changed)

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `id` | The value of the preference (NSNumber, String) |
| `key` | `String` | The preference name |

```javascript
acorn.setPreference_forKey(false, "drawMarchingAntsSelection");
```

<a id="acorn-takelayeredscreenshot"></a>

### `acorn.takeLayeredScreenshot()`

Takes a layered screenshot of all displays and returns a document for each display.

Returns: Array An array of documents, one for each connected display

```javascript
var documents = acorn.takeLayeredScreenshot();
for (var docIndex = 0; docIndex < documents.count(); docIndex++) {
    var doc = documents[docIndex];
    for (var layerIndex = 0; layerIndex < doc.layers().count(); layerIndex++) {
        print(doc.layers()[layerIndex].layerName());
    }
}
```

<a id="acorn-takelayeredscreenshotwithoptions"></a>

### `acorn.takeLayeredScreenshotWithOptions(options)`

Takes a layered screenshot of all displays and returns a document for each display.

| Parameter | Type | Description |
| --- | --- | --- |
| `options` | `Dictionary` | A set of options: &quot;hideShadows&quot;: bool, |

Returns: Array An array of documents, one for each connected display

```javascript
var documents = acorn.takeLayeredScreenshotWithOptions({hideShadows: true});
for (var docIndex = 0; docIndex < documents.count(); docIndex++) {
    var doc = documents[docIndex];
    for (var layerIndex = 0; layerIndex < doc.layers().count(); layerIndex++) {
        print(doc.layers()[layerIndex].layerName());
    }
}
```

<a id="acorn-toolpalette"></a>

### `acorn.toolPalette()`

Returns the tool palette for the current document, an ACToolPalette object.

```javascript
var palette = acorn.toolPalette();
print(palette.frontColor());
```

## Bitmap Layer

Bitmap layers are an extension of the [Layer](#layer) object and contain raster (bitmap) data.

<a id="bitmaplayer-applycifilternamed_withparameters"></a>

### `bitmapLayer.applyCIFilterNamed_withParameters(name, parameters)`

Applies a Core Image filter directly to the bitmap layer pixels. See also [layer.appendFilterWithName](#layerappendfilterwithnamename). Visit [cifilter.app](https://cifilter.app/) for a nice resource on the various filters you can use.

| Parameter | Type | Description |
| --- | --- | --- |
| `name` | `String` | The Core Image filter name. |
| `parameters` | `Object` | Filter input values keyed by Core Image input name. |

```javascript
var layer = acorn.currentDocument().currentLayer();
layer.applyCIFilterNamed_withParameters("CIBoxBlur", {inputRadius: 40});
```

<a id="bitmaplayer-applyciimagefromfilter"></a>

### `bitmapLayer.applyCIImageFromFilter(image)`

Replaces the bitmap layer contents with a CIImage.

| Parameter | Type | Description |
| --- | --- | --- |
| `image` | `CIImage` | Image to apply to the layer. |

```javascript
var layer = acorn.currentDocument().currentLayer();
var image = layer.CIImage();
var filter = CIFilter.colorPosterizeFilter()
filter.inputImage = image;
filter.levels = 6;
var filteredImage = filter.outputImage();
layer.applyCIImageFromFilter(filteredImage);
```

<a id="bitmaplayer-applyciimagefromfilter_shouldcliptoselection"></a>

### `bitmapLayer.applyCIImageFromFilter_shouldClipToSelection(image, clipToSelection)`

Applies a CIImage to the bitmap layer, optionally clipping the change to the active selection.

| Parameter | Type | Description |
| --- | --- | --- |
| `image` | `CIImage` | Image to apply to the layer. |
| `clipToSelection` | `Boolean` | True to restrict the result to the selection. |

```javascript
var layer = acorn.currentDocument().currentLayer();
var image = layer.CIImage();
var filter = CIFilter.gaussianBlurFilter();
filter.inputImage = image;
filter.radius = 20;
layer.applyCIImageFromFilter_shouldClipToSelection(filter.outputImage(), true);
```

<a id="bitmaplayer-coloratpoint"></a>

### `bitmapLayer.colorAtPoint(point)`

Returns the color of the bitmap layer at a canvas point.

| Parameter | Type | Description |
| --- | --- | --- |
| `point` | `NSPoint` | Point in canvas coordinates. |

Returns: NSColor The sampled color.

```javascript
var layer = acorn.currentDocument().currentLayer();
var color = layer.colorAtPoint(NSMakePoint(10, 10));
print(color);
```

<a id="bitmaplayer-fillwithcolor_shouldcliptoselection"></a>

### `bitmapLayer.fillWithColor_shouldClipToSelection(color, clipToSelection)`

Fills the bitmap layer, or the active selection, with a color.

| Parameter | Type | Description |
| --- | --- | --- |
| `color` | `NSColor` | Fill color. |
| `clipToSelection` | `Boolean` | True to restrict the fill to the active selection. |

```javascript
var layer = acorn.currentDocument().currentLayer();
layer.fillWithColor_shouldClipToSelection(NSColor.redColor(), true);
```

<a id="bitmaplayer-floodfillatpoint"></a>

### `bitmapLayer.floodFillAtPoint(point)`

Performs a flood fill on the bitmap layer at the given layer point.

| Parameter | Type | Description |
| --- | --- | --- |
| `point` | `NSPoint` | Point in layer coordinates. |

```javascript
var layer = acorn.currentDocument().currentLayer();
layer.floodFillAtPoint(NSMakePoint(25, 25));
```

<a id="bitmaplayer-frame"></a>

### `bitmapLayer.frame()`

Returns the bitmap layer frame in canvas coordinates.

Returns: NSRect The layer frame.

```javascript
var layer = acorn.currentDocument().currentLayer();
print(NSStringFromRect(layer.frame()));
```

<a id="bitmaplayer-frameorigin"></a>

### `bitmapLayer.frameOrigin()`

Returns the bitmap layer frame origin.

Returns: NSPoint The frame origin.

```javascript
var layer = acorn.currentDocument().currentLayer();
print(NSStringFromPoint(layer.frameOrigin()));
```

<a id="bitmaplayer-setframeorigin"></a>

### `bitmapLayer.setFrameOrigin(point)`

Moves the bitmap layer frame origin.

| Parameter | Type | Description |
| --- | --- | --- |
| `point` | `NSPoint` | New frame origin. |

```javascript
var layer = acorn.currentDocument().currentLayer();
layer.setFrameOrigin(NSMakePoint(20, 20));
```

## Document

A document is a general container for the whole image and allows access to varous IO routies, as well as the base group which holds layers. Is a subclass of NSDocument from AppKit.

<a id="document-autolevels"></a>

### `document.autoLevels()`

Adds a Levels filter to the current layer, and balances the levels automatically

```javascript
var doc = acorn.currentDocument();
doc.autoLevels();

// or target a specific layer:
doc.undo();
var layer = doc.layers()[1];
layer.autoLevels()
```

<a id="document-begincroppingwithrect"></a>

### `document.beginCroppingWithRect(rect)`

Starts an interactive crop operation with the given bounds.

| Parameter | Type | Description |
| --- | --- | --- |
| `rect` | `NSRect` | The crop rectangle in canvas coordinates. |

```javascript
 var doc = acorn.currentDocument();
 doc.beginCroppingWithRect(NSMakeRect(100, 100, 400, 300));
```

<a id="document-bitspercomponent"></a>

### `document.bitsPerComponent()`

Returns the number of bits per color component.

Returns: Number 8, 16, or 32.

```javascript
print(acorn.currentDocument().bitsPerComponent());
```

<a id="document-bitsperpixel"></a>

### `document.bitsPerPixel()`

Returns the number of bits per pixel.

Returns: Number 32, 64, or 128.

```javascript
print(acorn.currentDocument().bitsPerPixel());
```

<a id="document-callfilternamed"></a>

### `document.callFilterNamed(filterOrPlugin)`

Invokes a filter / plugin via the given string

| Parameter | Type | Description |
| --- | --- | --- |
| `filterOrPlugin` | `String` | The filter or plugin name |

```javascript
var doc = acorn.currentDocument();
doc.callFilterNamed("CIColorInvert");
doc.callFilterNamed("New Image With Curved Drop Shadow");
```

<a id="document-canvassize"></a>

### `document.canvasSize()`

Returns the size of the image.

Returns: NSSize The image size.

```javascript
 var size = acorn.currentDocument().canvasSize();
 print(size.width + "x" + size.height);
```

<a id="document-ciimage"></a>

### `document.CIImage()`

Returns a Core Image composite of the document&#x27;s visible layers.

Returns: CIImage The composited image.

```javascript
 var doc = acorn.currentDocument();
 var image = doc.CIImage();
 print(image);
```

<a id="document-colorspace"></a>

### `document.colorSpace()`

Returns the document CGColorSpace.

Returns: CGColorSpaceRef The document color space.

```javascript
var colorSpace = acorn.currentDocument().colorSpace();
print(colorSpace);
```

<a id="document-copymerged"></a>

### `document.copyMerged()`

Writes a composite of the image to the clipboard.

```javascript
var doc = acorn.currentDocument();
doc.copyMerged();
```

<a id="document-croptorect"></a>

### `document.cropToRect(rect)`

Crops the document to the given rectangle.

| Parameter | Type | Description |
| --- | --- | --- |
| `rect` | `NSRect` | The crop rectangle in canvas coordinates. |

```javascript
var doc = acorn.currentDocument();
doc.cropToRect(NSMakeRect(100, 100, 400, 400));
```

<a id="document-currentlayer"></a>

### `document.currentLayer()`

Returns the document&#x27;s selected layer.

Returns: Layer The current layer.

```javascript
var layer = acorn.currentDocument().currentLayer();
print(layer.layerName());
```

<a id="document-dpi"></a>

### `document.DPI()`

Returns the document resolution in dots per inch.

Returns: double The document DPI.

```javascript
 var dpi = acorn.currentDocument().DPI();
 print(dpi);
```

<a id="document-duplicate"></a>

### `document.duplicate()`

Duplicates the image

Returns: Document a copy of the invoked image.

```javascript
var doc = acorn.currentDocument();
var newDoc = doc.duplicate();
```

<a id="document-expandcanvastofitlayers"></a>

### `document.expandCanvasToFitLayers()`

Grows the size of the canvas to show any pixels outside the frame of the image.

```javascript
var doc = acorn.currentDocument();
doc.rotateCanvas(45);
doc.expandCanvasToFitLayers();
```

<a id="document-firstlayerwithname"></a>

### `document.firstLayerWithName(layerName)`

Returns the first layer in the document with the given name.

| Parameter | Type | Description |
| --- | --- | --- |
| `layerName` | `String` | The layer name to find. |

Returns: Layer The matching layer, or null if no layer matches.

```javascript
var layer = acorn.currentDocument().firstLayerWithName("Background");
if (layer) {
    layer.setVisible(false);
}
```

<a id="document-flipcanvaswithdirection"></a>

### `document.flipCanvasWithDirection(direction)`

Flips the canvas in the given direction.

| Parameter | Type | Description |
| --- | --- | --- |
| `direction` | `String` | either &quot;vertical&quot; or &quot;horizontal&quot; |

```javascript
var doc = acorn.currentDocument();
 doc.flipCanvasWithDirection("vertical");
```

<a id="document-invertselection"></a>

### `document.invertSelection()`

Inverts the current selection

```javascript
var doc = acorn.currentDocument();
doc.selectFrame(NSMakeRect(100, 100, 400, 400));
doc.invertSelection();
```

<a id="document-layers"></a>

### `document.layers()`

Returns the document&#x27;s top-level layers.

Returns: NSArray The top-level layers.

```javascript
 var doc = acorn.currentDocument();
 for (var i = 0; i < doc.layers().count(); i++) {
 print(doc.layers()[i].layerName());
 }
```

<a id="document-mergevisiblelayers"></a>

### `acorn.mergeVisibleLayers()`

Merges all the visible layers in the image.

```javascript
var doc = acorn.currentDocument();
doc.mergeVisibleLayers();
```

<a id="document-newcgimage"></a>

### `document.newCGImage()`

Creates a new CGImage containing the current composited document image.

Returns: CGImageRef A retained CGImage for the document composite.

```javascript
 var doc = acorn.currentDocument();
 var image = doc.newCGImage();
 print(image);
```

<a id="document-newlayerwithnsimage"></a>

### `document.newLayerWithNSImage(image)`

Adds a new bitmap layer from an NSImage.

| Parameter | Type | Description |
| --- | --- | --- |
| `image` | `NSImage` | The image to place in the new layer. |

```javascript
 var image = NSImage.alloc().initWithContentsOfFile("/tmp/source.png");
 acorn.currentDocument().newLayerWithNSImage(image);
```

<a id="document-replaceoccurrencesofstring_withstring"></a>

### `document.replaceOccurrencesOfString_withString(target, replacement)`

Replaces matching text in the document&#x27;s text shapes.

| Parameter | Type | Description |
| --- | --- | --- |
| `target` | `String` | The text to find. |
| `replacement` | `String` | The replacement text. |

```javascript
var doc = acorn.currentDocument();
doc.replaceOccurrencesOfString_withString("Draft", "Final");
```

<a id="document-resizeimagetosize"></a>

### `document.resizeImageToSize(size)`

Resizes the document canvas to the given size without scaling layer contents.

| Parameter | Type | Description |
| --- | --- | --- |
| `size` | `NSSize` | The new canvas size. |

```javascript
acorn.currentDocument().resizeImageToSize(NSMakeSize(1000, 1000));
```

<a id="document-rotatecanvas"></a>

### `document.rotateCanvas(angle)`

Rotates the image with the given angle (in degrees).

| Parameter | Type | Description |
| --- | --- | --- |
| `angle` | `Number` | Angle in degrees |

```javascript
var doc = acorn.currentDocument();
doc.rotateCanvas(45);
doc.expandCanvasToFitLayers();
```

<a id="document-scalecanvastosize"></a>

### `document.scaleCanvasToSize(size)`

Scales the canvas and all layers to the given size.

| Parameter | Type | Description |
| --- | --- | --- |
| `size` | `NSSize` | The new image size. |

```javascript
 var doc = acorn.currentDocument();
 doc.scaleCanvasToSize(NSMakeSize(800, 600));
```

<a id="document-scaleimagetoheight"></a>

### `document.scaleImageToHeight(height)`

Scales the image proportionally to the given height.

| Parameter | Type | Description |
| --- | --- | --- |
| `height` | `Number` | The target height in pixels. |

```javascript
acorn.currentDocument().scaleImageToHeight(900);
```

<a id="document-scaleimagetosize"></a>

### `document.scaleImageToSize(size)`

Scales the image and all layers to the given size.

| Parameter | Type | Description |
| --- | --- | --- |
| `size` | `NSSize` | The new image size. |

```javascript
acorn.currentDocument().scaleImageToSize(NSMakeSize(1000, 1000));
```

<a id="document-scaleimagetowidth"></a>

### `document.scaleImageToWidth(width)`

Scales the image proportionally to the given width.

| Parameter | Type | Description |
| --- | --- | --- |
| `width` | `Number` | The target width in pixels. |

```javascript
acorn.currentDocument().scaleImageToWidth(1600);
```

<a id="document-scaleimagewithpercentage"></a>

### `document.scaleImageWithPercentage(scale)`

Scales the image by a multiplier.

| Parameter | Type | Description |
| --- | --- | --- |
| `scale` | `Number` | Scale multiplier, where 0.5 is 50 percent and 2.0 is 200 percent. |

```javascript
acorn.currentDocument().scaleImageWithPercentage(0.5);
```

<a id="document-selectframe"></a>

### `document.selectFrame(frame)`

Adds a rectangular selection to the image

| Parameter | Type | Description |
| --- | --- | --- |
| `frame` | `NSRect` | The selection bounds |

```javascript
var doc = acorn.currentDocument();
doc.selectFrame(NSMakeRect(100, 100, 400, 400));
doc.invertSelection();
```

<a id="document-setbitsperpixel"></a>

### `document.setBitsPerPixel(bitsPerPixel)`

Sets the document bit depth. Valid values are 32, 64, and 128.

| Parameter | Type | Description |
| --- | --- | --- |
| `bitsPerPixel` | `Number` | The target bits per pixel. |

```javascript
acorn.currentDocument().setBitsPerPixel(64);
```

<a id="document-setcanvassize"></a>

### `document.setCanvasSize(size)`

Changes the canvas size without scaling layer contents, anchored at the lower-left corner.

| Parameter | Type | Description |
| --- | --- | --- |
| `size` | `NSSize` | The new canvas size. |

```javascript
 var doc = acorn.currentDocument();
 doc.setCanvasSize(NSMakeSize(1200, 800));
```

<a id="document-setcanvassize_usinganchor"></a>

### `document.setCanvasSize_usingAnchor(size, anchor)`

Changes the canvas size without scaling layer contents, with an argument to anchor the existing image to a corner.

| Parameter | Type | Description |
| --- | --- | --- |
| `size` | `NSSize` | The new canvas size. |
| `anchor` | `NSString` | The area to anchor to. Valid values are &quot;bottom center&quot;, &quot;bottom left&quot;, &quot;bottom right&quot;, &quot;middle center&quot;, &quot;middle left&quot;, &quot;middle right&quot;, &quot;top center&quot;, &quot;top left&quot;, &quot;top right&quot; |

```javascript
var doc = acorn.currentDocument();
doc.setCanvasSize_usingAnchor(NSMakeSize(1000, 1000), "top left");
```

<a id="document-setdpi"></a>

### `document.setDPI(dpi)`

Sets the document resolution in dots per inch.

| Parameter | Type | Description |
| --- | --- | --- |
| `dpi` | `double` | The new document DPI. |

```javascript
 acorn.currentDocument().setDPI(144);
```

<a id="document-setselectedlayer"></a>

### `document.setSelectedLayer(layer)`

Sets the actively selected layer.

| Parameter | Type | Description |
| --- | --- | --- |
| `layer` | `Layer` | The layer to select |

```javascript
var doc = acorn.currentDocument();
var bitmapLayer = doc.baseGroup().addBitmapLayer();
doc.setSelectedLayer(bitmapLayer);
```

<a id="document-trim"></a>

### `document.trim()`

Trims the edge colors out of the image.

```javascript
var doc = acorn.currentDocument();
doc.trim();
```

<a id="document-writetofile_withuti"></a>

### `document.writeToFile_withUTI(path, uti)`

Writes the document to a file using the given Uniform Type Identifier.

| Parameter | Type | Description |
| --- | --- | --- |
| `path` | `String` | Destination file path. |
| `uti` | `String` | Uniform Type Identifier for the output format. |

Returns: Boolean True when the write succeeds.

```javascript
var doc = acorn.currentDocument();
doc.writeToFile_withUTI("/tmp/export.png", "public.png");
```

## Graphics

<a id="bezieranchor-hasleftsegment"></a>

### `bezierAnchor.hasLeftSegment()`

Returns whether the anchor has a segment to its left.

Returns: Boolean True when a left segment exists.

```javascript
var anchor = acorn.currentDocument().currentLayer().graphics()[0].path().anchors()[0];
print(anchor.hasLeftSegment());
```

<a id="bezieranchor-hasrightsegment"></a>

### `bezierAnchor.hasRightSegment()`

Returns whether the anchor has a segment to its right.

Returns: Boolean True when a right segment exists.

```javascript
var anchor = acorn.currentDocument().currentLayer().graphics()[0].path().anchors()[0];
print(anchor.hasRightSegment());
```

<a id="bezieranchor-leftcp"></a>

### `bezierAnchor.leftCP()`

Returns the left control point for the anchor.

Returns: NSPoint The left control point.

```javascript
var anchor = acorn.currentDocument().currentLayer().graphics()[0].path().anchors()[0];
print(NSStringFromPoint(anchor.leftCP()));
```

<a id="bezieranchor-leftsegmenttype"></a>

### `bezierAnchor.leftSegmentType()`

Returns the NSBezierPathElement type for the segment to the left of the anchor.

Returns: Number The segment type.

```javascript
var anchor = acorn.currentDocument().currentLayer().graphics()[0].path().anchors()[0];
print(anchor.leftSegmentType());
```

<a id="bezieranchor-location"></a>

### `bezierAnchor.location()`

Returns the anchor location.

Returns: NSPoint The anchor location.

```javascript
var path = acorn.currentDocument().currentLayer().graphics()[0].path();
var anchor = path.anchors()[0];
print(NSStringFromPoint(anchor.location()));
```

<a id="bezieranchor-rightcp"></a>

### `bezierAnchor.rightCP()`

Returns the right control point for the anchor.

Returns: NSPoint The right control point.

```javascript
var anchor = acorn.currentDocument().currentLayer().graphics()[0].path().anchors()[0];
print(NSStringFromPoint(anchor.rightCP()));
```

<a id="bezieranchor-rightsegmenttype"></a>

### `bezierAnchor.rightSegmentType()`

Returns the NSBezierPathElement type for the segment to the right of the anchor.

Returns: Number The segment type.

```javascript
var anchor = acorn.currentDocument().currentLayer().graphics()[0].path().anchors()[0];
print(anchor.rightSegmentType());
```

<a id="bezieranchor-setleftcp"></a>

### `bezierAnchor.setLeftCP(point)`

Sets the left control point for the anchor.

| Parameter | Type | Description |
| --- | --- | --- |
| `point` | `NSPoint` | The new left control point. |

```javascript
var anchor = acorn.currentDocument().currentLayer().graphics()[0].path().anchors()[0];
anchor.setLeftCP(NSMakePoint(25, 50));
```

<a id="bezieranchor-setleftsegmenttype"></a>

### `bezierAnchor.setLeftSegmentType(type)`

Sets the NSBezierPathElement type for the segment to the left of the anchor.

| Parameter | Type | Description |
| --- | --- | --- |
| `type` | `Number` | The segment type. |

```javascript
var anchor = acorn.currentDocument().currentLayer().graphics()[0].path().anchors()[0];
anchor.setLeftSegmentType(NSBezierPathElementLineTo);
```

<a id="bezieranchor-setlocation"></a>

### `bezierAnchor.setLocation(point)`

Moves the anchor to a new location.

| Parameter | Type | Description |
| --- | --- | --- |
| `point` | `NSPoint` | The new anchor location. |

```javascript
var path = acorn.currentDocument().currentLayer().graphics()[0].path();
path.anchors()[0].setLocation(NSMakePoint(50, 50));
```

<a id="bezieranchor-setrightcp"></a>

### `bezierAnchor.setRightCP(point)`

Sets the right control point for the anchor.

| Parameter | Type | Description |
| --- | --- | --- |
| `point` | `NSPoint` | The new right control point. |

```javascript
var anchor = acorn.currentDocument().currentLayer().graphics()[0].path().anchors()[0];
anchor.setRightCP(NSMakePoint(75, 50));
```

<a id="bezieranchor-setrightsegmenttype"></a>

### `bezierAnchor.setRightSegmentType(type)`

Sets the NSBezierPathElement type for the segment to the right of the anchor.

| Parameter | Type | Description |
| --- | --- | --- |
| `type` | `Number` | The segment type. |

```javascript
var anchor = acorn.currentDocument().currentLayer().graphics()[0].path().anchors()[0];
anchor.setRightSegmentType(NSBezierPathElementLineTo);
```

<a id="bezieranchor-translateby"></a>

### `bezierAnchor.translateBy(delta)`

Moves the anchor and its control points by a delta.

| Parameter | Type | Description |
| --- | --- | --- |
| `delta` | `NSPoint` | Translation delta. |

```javascript
var anchor = acorn.currentDocument().currentLayer().graphics()[0].path().anchors()[0];
anchor.translateBy(NSMakePoint(10, 0));
```

<a id="beziergraphic-acbezierpath"></a>

### `bezierGraphic.ACBezierPath()`

Returns the Acorn Bezier path for a Bezier graphic.

Returns: BezierPath The graphic&#x27;s Bezier path.

```javascript
var bezier = acorn.currentDocument().currentLayer().graphics()[0];
print(bezier.ACBezierPath().anchorCount());
```

<a id="beziergraphic-movepointatindex_topoint"></a>

### `bezierGraphic.movePointAtIndex_toPoint(index, point)`

Moves a Bezier path point to a new location.

| Parameter | Type | Description |
| --- | --- | --- |
| `index` | `Number` | Point index. |
| `point` | `NSPoint` | New point location. |

```javascript
var bezier = acorn.currentDocument().currentLayer().graphics()[0];
bezier.movePointAtIndex_toPoint(0, NSMakePoint(50, 50));
```

<a id="beziergraphic-path"></a>

### `bezierGraphic.path()`

Returns the Bezier path for a Bezier graphic.

Returns: BezierPath The graphic&#x27;s Bezier path.

```javascript
var bezier = acorn.currentDocument().currentLayer().graphics()[0];
print(bezier.path().anchorCount());
```

<a id="beziergraphic-pointofelementatindex"></a>

### `bezierGraphic.pointOfElementAtIndex(index)`

Returns the point for a Bezier path element.

| Parameter | Type | Description |
| --- | --- | --- |
| `index` | `Number` | Element index. |

Returns: NSPoint The element point.

```javascript
var bezier = acorn.currentDocument().currentLayer().graphics()[0];
print(NSStringFromPoint(bezier.pointOfElementAtIndex(0)));
```

<a id="beziergraphic-setacbezierpath"></a>

### `bezierGraphic.setACBezierPath(path)`

Replaces a Bezier graphic&#x27;s Acorn Bezier path.

| Parameter | Type | Description |
| --- | --- | --- |
| `path` | `BezierPath` | The replacement path. |

```javascript
var bezier = acorn.currentDocument().currentLayer().graphics()[0];
var path = bezier.ACBezierPath();
bezier.setACBezierPath(path);
```

<a id="beziergraphic-setpath"></a>

### `bezierGraphic.setPath(path)`

Replaces the Bezier path for a Bezier graphic.

| Parameter | Type | Description |
| --- | --- | --- |
| `path` | `BezierPath` | The replacement path. |

```javascript
var bezier = acorn.currentDocument().currentLayer().graphics()[0];
var path = bezier.path();
bezier.setPath(path);
```

<a id="bezierpath-anchoratindex"></a>

### `bezierPath.anchorAtIndex(index)`

Returns the anchor at the given index.

| Parameter | Type | Description |
| --- | --- | --- |
| `index` | `Number` | Anchor index. |

Returns: BezierAnchor The anchor object.

```javascript
var path = acorn.currentDocument().currentLayer().graphics()[0].path();
var anchor = path.anchorAtIndex(0);
print(NSStringFromPoint(anchor.location()));
```

<a id="bezierpath-anchorcount"></a>

### `bezierPath.anchorCount()`

Returns the number of anchors in the Bezier path.

Returns: Number The anchor count.

```javascript
var path = acorn.currentDocument().currentLayer().graphics()[0].path();
print(path.anchorCount());
```

<a id="bezierpath-anchors"></a>

### `bezierPath.anchors()`

Returns the anchors in the Bezier path.

Returns: NSArray The path anchors.

```javascript
var path = acorn.currentDocument().currentLayer().graphics()[0].path();
for (var i = 0; i < path.anchors().count(); i++) {
    print(NSStringFromPoint(path.anchors()[i].location()));
}
```

<a id="bezierpath-locationforanchoratindex"></a>

### `bezierPath.locationForAnchorAtIndex(index)`

Returns the location for an anchor at the given index.

| Parameter | Type | Description |
| --- | --- | --- |
| `index` | `Number` | Anchor index. |

Returns: NSPoint The anchor location.

```javascript
var path = acorn.currentDocument().currentLayer().graphics()[0].path();
print(NSStringFromPoint(path.locationForAnchorAtIndex(0)));
```

<a id="bezierpath-resetanchors"></a>

### `bezierPath.resetAnchors()`

Converts curve anchors to straight line anchors by resetting their control points.

```javascript
var path = acorn.currentDocument().currentLayer().graphics()[0].path();
path.resetAnchors();
```

<a id="bezierpath-setlocation_foranchoratindex"></a>

### `bezierPath.setLocation_forAnchorAtIndex(point, index)`

Moves the anchor at the given index to a new location.

| Parameter | Type | Description |
| --- | --- | --- |
| `point` | `NSPoint` | New anchor location. |
| `index` | `Number` | Anchor index. |

```javascript
var path = acorn.currentDocument().currentLayer().graphics()[0].path();
path.setLocation_forAnchorAtIndex(NSMakePoint(50, 50), 0);
```

<a id="graphic-bezierpath"></a>

### `graphic.bezierPath()`

Returns the graphic as an NSBezierPath.

Returns: NSBezierPath The graphic path.

```javascript
var graphic = acorn.currentDocument().currentLayer().graphics()[0];
var path = graphic.bezierPath();
print(path.bounds());
```

<a id="graphic-bounds"></a>

### `graphic.bounds()`

Returns the graphic bounds.

Returns: NSRect The graphic bounds.

```javascript
var graphic = acorn.currentDocument().currentLayer().graphics()[0];
print(NSStringFromRect(graphic.bounds()));
```

<a id="graphic-drawsfill"></a>

### `graphic.drawsFill`

Gets or sets whether the graphic draws its fill.

```javascript
var graphic = acorn.currentDocument().currentLayer().graphics()[0];
print(graphic.drawsFill());
graphic.setDrawsFill(true);
```

<a id="graphic-fillcolor"></a>

### `graphic.fillColor()`

Returns the graphic fill color.

Returns: NSColor The fill color.

```javascript
var graphic = acorn.currentDocument().currentLayer().graphics()[0];
print(graphic.fillColor());
```

<a id="graphic-scalexby_yby"></a>

### `graphic.scaleXBy_yBy(xScale, yScale)`

Scales a graphic&#x27;s bounds, stroke, and shadow by the given multipliers.

| Parameter | Type | Description |
| --- | --- | --- |
| `xScale` | `Number` | Horizontal scale multiplier. |
| `yScale` | `Number` | Vertical scale multiplier. |

```javascript
var graphic = acorn.currentDocument().currentLayer().graphics()[0];
graphic.scaleXBy_yBy(2.0, 2.0);
```

<a id="graphic-setfillcolor"></a>

### `graphic.setFillColor(color)`

Sets the graphic fill color.

| Parameter | Type | Description |
| --- | --- | --- |
| `color` | `NSColor` | The new fill color. |

```javascript
var graphic = acorn.currentDocument().currentLayer().graphics()[0];
graphic.setFillColor(NSColor.redColor());
```

<a id="graphic-setstrokecolor"></a>

### `graphic.setStrokeColor(color)`

Sets the graphic stroke color.

| Parameter | Type | Description |
| --- | --- | --- |
| `color` | `NSColor` | The new stroke color. |

```javascript
var graphic = acorn.currentDocument().currentLayer().graphics()[0];
graphic.setStrokeColor(NSColor.blueColor());
```

<a id="graphic-setstrokelinewidth"></a>

### `graphic.setStrokeLineWidth(width)`

Alias for graphic.setStrokeWidth.

| Parameter | Type | Description |
| --- | --- | --- |
| `width` | `Number` | The new stroke width. |

```javascript
var graphic = acorn.currentDocument().currentLayer().graphics()[0];
graphic.setStrokeLineWidth(4);
```

<a id="graphic-setstrokewidth"></a>

### `graphic.setStrokeWidth(width)`

Sets the graphic stroke width.

| Parameter | Type | Description |
| --- | --- | --- |
| `width` | `Number` | The new stroke width. |

```javascript
var graphic = acorn.currentDocument().currentLayer().graphics()[0];
graphic.setStrokeWidth(4);
```

<a id="graphic-settextstroke"></a>

### `graphic.setTextStroke(width)`

Sets the text stroke width for a text graphic.

| Parameter | Type | Description |
| --- | --- | --- |
| `width` | `Number` | The new text stroke width. |

```javascript
var text = acorn.currentDocument().currentLayer().graphics()[0];
text.setTextStroke(2);
```

<a id="graphic-strokecolor"></a>

### `graphic.strokeColor()`

Returns the graphic stroke color.

Returns: NSColor The stroke color.

```javascript
var graphic = acorn.currentDocument().currentLayer().graphics()[0];
print(graphic.strokeColor());
```

<a id="graphic-strokelinewidth"></a>

### `graphic.strokeLineWidth()`

Alias for graphic.strokeWidth.

Returns: Number The stroke width.

```javascript
var graphic = acorn.currentDocument().currentLayer().graphics()[0];
print(graphic.strokeLineWidth());
```

<a id="graphic-strokewidth"></a>

### `graphic.strokeWidth()`

Returns the graphic stroke width.

Returns: Number The stroke width.

```javascript
var graphic = acorn.currentDocument().currentLayer().graphics()[0];
print(graphic.strokeWidth());
```

<a id="graphic-textfillcolor"></a>

### `graphic.textFillColor()`

Returns the text fill color for a text graphic.

Returns: NSColor The text fill color.

```javascript
var text = acorn.currentDocument().currentLayer().graphics()[0];
print(text.textFillColor());
```

<a id="graphic-textstrokecolor"></a>

### `graphic.textStrokeColor()`

Returns the text stroke color for a text graphic.

Returns: NSColor The text stroke color.

```javascript
var text = acorn.currentDocument().currentLayer().graphics()[0];
print(text.textStrokeColor());
```

<a id="polygongraphic-scalexby_yby"></a>

### `polygonGraphic.scaleXBy_yBy(xScale, yScale)`

Scales a polygon graphic by the given multipliers.

| Parameter | Type | Description |
| --- | --- | --- |
| `xScale` | `Number` | Horizontal scale multiplier. |
| `yScale` | `Number` | Vertical scale multiplier. |

```javascript
var polygon = acorn.currentDocument().currentLayer().graphics()[0];
polygon.scaleXBy_yBy(1.5, 1.5);
```

<a id="stargraphic-scalexby_yby"></a>

### `starGraphic.scaleXBy_yBy(xScale, yScale)`

Scales a star graphic by the given multipliers.

| Parameter | Type | Description |
| --- | --- | --- |
| `xScale` | `Number` | Horizontal scale multiplier. |
| `yScale` | `Number` | Vertical scale multiplier. |

```javascript
var star = acorn.currentDocument().currentLayer().graphics()[0];
star.scaleXBy_yBy(1.5, 1.5);
```

<a id="textgraphic-sethtmlstring"></a>

### `textGraphic.setHTMLString(html)`

Replaces a text graphic&#x27;s contents with HTML.

| Parameter | Type | Description |
| --- | --- | --- |
| `html` | `String` | HTML string to use as text contents. |

```javascript
var text = acorn.currentDocument().currentLayer().graphics()[0];
text.setHTMLString("<b>Hello</b> from JavaScript");
```

<a id="textgraphic-setstring"></a>

### `textGraphic.setString(string)`

Replaces a text graphic&#x27;s plain string contents.

| Parameter | Type | Description |
| --- | --- | --- |
| `string` | `String` | New text contents. |

```javascript
var text = acorn.currentDocument().currentLayer().graphics()[0];
text.setString("Hello from JavaScript");
```

## Group Layer

A group layer contains zero or more sub-layers, as well as possibly containing additional group layers which can contain their own layers. Group layer extends [Layer](#layer).

<a id="grouplayer-addbitmaplayer"></a>

### `groupLayer.addBitmapLayer()`

Adds a new bitmap layer to the group.

Returns: BitmapLayer The new bitmap layer.

```javascript
var bitmapLayer = acorn.currentDocument().baseGroup().addBitmapLayer();
bitmapLayer.fillWithColor_shouldClipToSelection(NSColor.redColor(), false);
```

<a id="grouplayer-addgrouplayer"></a>

### `groupLayer.addGroupLayer()`

Adds a new group layer to the group.

Returns: GroupLayer The new group layer.

```javascript
var group = acorn.currentDocument().baseGroup().addGroupLayer();
group.setLayerName("Generated Group");
```

<a id="grouplayer-addshapelayer"></a>

### `groupLayer.addShapeLayer()`

Adds a new shape layer to the group.

Returns: ShapeLayer The new shape layer.

```javascript
var shapeLayer = acorn.currentDocument().baseGroup().addShapeLayer();
shapeLayer.setLayerName("Generated Shapes");
```

<a id="grouplayer-insertcgimage_atindex_withname"></a>

### `groupLayer.insertCGImage_atIndex_withName(image, index, layerName)`

Inserts a CGImage into the group as a bitmap layer.

| Parameter | Type | Description |
| --- | --- | --- |
| `image` | `CGImageRef` | Image to insert. |
| `index` | `Number` | Insertion index. |
| `layerName` | `String` | Name for the new layer. |

Returns: BitmapLayer The inserted bitmap layer.

```javascript
var doc = acorn.currentDocument();
var image = doc.newCGImage();
doc.baseGroup().insertCGImage_atIndex_withName(image, 0, "Composite Copy");
```

<a id="grouplayer-insertciimage_atindex_withname"></a>

### `groupLayer.insertCIImage_atIndex_withName(image, index, layerName)`

Inserts a CIImage into the group as a bitmap layer.

| Parameter | Type | Description |
| --- | --- | --- |
| `image` | `CIImage` | Image to insert. |
| `index` | `Number` | Insertion index. |
| `layerName` | `String` | Name for the new layer. |

Returns: BitmapLayer The inserted bitmap layer.

```javascript
var doc = acorn.currentDocument();

var filter = CIFilter.checkerboardGeneratorFilter();
filter.setDefaults();
filter.color0 = CIColor.redColor();
filter.color1 = CIColor.blueColor();
filter.width = 25;
filter.sharpness = 1.0;

var img = filter.outputImage();
var canvasSize = doc.canvasSize();
img = img.imageByCroppingToRect(CGRectMake(0, 0, canvasSize.width, canvasSize.height));

doc.baseGroup().insertCIImage_atIndex_withName(img, 1, "Checkerboard");
```

<a id="grouplayer-insertimagewithpath_atindex_withname"></a>

### `groupLayer.insertImageWithPath_atIndex_withName(path, index, layerName)`

Inserts an image file into the group as a bitmap layer.

| Parameter | Type | Description |
| --- | --- | --- |
| `path` | `String` | Path to the image file. |
| `index` | `Number` | Insertion index. |
| `layerName` | `String` | Name for the new layer. |

Returns: BitmapLayer The inserted bitmap layer.

```javascript
var group = acorn.currentDocument().baseGroup();
var layer = group.insertImageWithPath_atIndex_withName("/tmp/source.png", 0, "Imported Image");
print(layer.layerName());
```

<a id="grouplayer-insertlayerwithimagepath_atindex"></a>

### `document.insertLayerWithImagePath_atIndex(imagePath, index)`

Adds a new layer with the image from imagePath, and inserts it at the given index.

| Parameter | Type | Description |
| --- | --- | --- |
| `imagePath` | `String` | Path to the image file. |
| `index` | `Number` | Insertion index. |

Returns: BitmapLayer The inserted bitmap layer.

```javascript
var doc = acorn.open("/Volumes/srv/Users/gus/Pictures/MyImage.acorn");
var layer = doc.layers()[0];
doc.setSelectedLayer(layer);

// 0 puts it at the bottom. 1 or higher would put it on top..
var newLayer = doc.baseGroup().insertLayerWithImagePath_atIndex("/Volumes/srv/Users/gus/Pictures/AnotherImage.png", 3)
```

## Layer

A base class that all layer types (bitmap, shape, and group) inherit from. Is a subclass of NSObject from AppKit.

<a id="layer-addmask"></a>

### `layer.addMask()`

Adds a mask to the layer. If a selection exists, the mask is initialized from it.

```javascript
var layer = acorn.currentDocument().currentLayer();
layer.addMask();
```

<a id="layer-appendfilterwithname"></a>

### `layer.appendFilterWithName(name)`

Appends a Core Image filter to the layer&#x27;s filter chain. This will also bring up the filter palette where you can change the various settings for this filter. Visit [cifilter.app](https://cifilter.app/) for a nice resource on the various filters you can use.

| Parameter | Type | Description |
| --- | --- | --- |
| `name` | `String` | The Core Image filter name. |

```javascript
var layer = acorn.currentDocument().currentLayer();
layer.appendFilterWithName("CIGaussianBlur");
```

<a id="layer-appendfilterwithname_parameters"></a>

### `layer.appendFilterWithName_parameters(name, parameters)`

Appends a Core Image filter to the layer&#x27;s filter chain and applies input parameters.

| Parameter | Type | Description |
| --- | --- | --- |
| `name` | `String` | The Core Image filter name. |
| `parameters` | `Object` | Filter input values keyed by Core Image input name. |

```javascript
var layer = acorn.currentDocument().currentLayer();
layer.appendFilterWithName_parameters("CIGaussianBlur", {inputRadius: 8});
```

<a id="layer-autolevels"></a>

### `layer.autoLevels()`

Adds a Levels filter to the given layer, and balances the levels automatically

```javascript
var doc = acorn.currentDocument();
var layer = doc.layers()[0];
layer.autoLevels()
```

<a id="layer-bounds"></a>

### `layer.bounds()`

Returns the layer bounds.

Returns: NSRect The layer bounds.

```javascript
var layer = acorn.currentDocument().currentLayer();
print(NSStringFromRect(layer.bounds()));
```

<a id="layer-compositingmode"></a>

### `layer.compositingMode`

Gets or sets the layer compositing mode as a [CGBlendMode](https://developer.apple.com/documentation/coregraphics/cgblendmode) value.

```javascript
var layer = acorn.currentDocument().currentLayer();
print(layer.compositingMode());
layer.setCompositingMode(kCGBlendModeMultiply);
```

<a id="layer-layername"></a>

### `layer.layerName`

Gets or sets the layer name.

```javascript
var layer = acorn.currentDocument().currentLayer();
print(layer.layerName());
layer.setLayerName("Updated Layer Name");
```

<a id="layer-layertype"></a>

### `layer.layerType()`

Returns the layer type constant.

Returns: Number The layer type, such as ACBitmapLayer, ACShapeLayer, ACGroupLayer, or ACMaskLayer.

```javascript
var layer = acorn.currentDocument().currentLayer();

if (layer.layerType() == ACBitmapLayer) {
  print("It’s a bitmap layer");
}
else if (layer.layerType() == ACShapeLayer) {
  print("It’s a shape layer");
}
else if (layer.layerType() == ACGroupLayer) {
  print("It’s a group layer");
}
else if (layer.layerType() == ACMaskLayer) {
  print("It’s a mask layer");
}

print(layer.layerType());
```

<a id="layer-loadfilterpresetwithname"></a>

### `layer.loadFilterPresetWithName(name)`

Loads a saved layer filter preset onto the layer.

| Parameter | Type | Description |
| --- | --- | --- |
| `name` | `String` | The filter preset name. |

```javascript
var layer = acorn.currentDocument().currentLayer();
layer.loadFilterPresetWithName("Checkered Brush");
```

<a id="layer-mask"></a>

### `layer.mask()`

Returns the layer mask.

Returns: MaskLayer The mask layer, or null if the layer has no mask.

```javascript
var mask = acorn.currentDocument().currentLayer().mask();
if (mask) {
    print(NSStringFromRect(mask.frame()));
}
```

<a id="layer-maskislinked"></a>

### `layer.maskIsLinked()`

Returns whether the layer mask moves with the layer. See also [setMaskIsLinked](#layersetmaskislinkedlinked)

Returns: Boolean True when the mask is linked to the layer.

```javascript
var layer = acorn.currentDocument().currentLayer();
print(layer.maskIsLinked());
```

<a id="layer-opacity"></a>

### `layer.opacity`

Gets or sets the layer opacity as a floating-point value from 0.0 to 1.0.

```javascript
var layer = acorn.currentDocument().currentLayer();
print(layer.opacity());
layer.setOpacity(0.5);
```

<a id="layer-opaqueframe"></a>

### `layer.opaqueFrame()`

Returns the layer&#x27;s opaque bounds in canvas coordinates. You could use these bounds to trim the image, or start a crop.

Returns: NSRect The opaque layer frame.

```javascript
var layer = acorn.currentDocument().currentLayer();
print(NSStringFromRect(layer.opaqueFrame()));

acorn.currentDocument().beginCroppingWithRect(layer.opaqueFrame());
```

<a id="layer-renderedciimage"></a>

### `layer.renderedCIImage()`

Returns a Core Image rendering of the layer with opacity, filters, mask, and blending applied.

Returns: CIImage The rendered layer image.

```javascript
var layer = acorn.currentDocument().currentLayer();
var image = layer.renderedCIImage();
print(image.extent());
```

<a id="layer-setblendmode"></a>

### `layer.setBlendMode(blendString)`

Changes the blend (composite) mode of the layer. Valid values are: &quot;passThrough&quot;, &quot;normal&quot;, &quot;multiply&quot;, &quot;screen&quot;, &quot;overlay&quot;, &quot;darken&quot;, &quot;lighten&quot;, &quot;colorDodge&quot;, &quot;colorBurn&quot;, &quot;softLight&quot;, &quot;hardLight&quot;, &quot;difference&quot;, &quot;exclusion&quot;, &quot;hue&quot;, &quot;saturation&quot;, &quot;color&quot;, &quot;luminosity&quot;, &quot;clear&quot;, &quot;copy&quot;, &quot;copyOpaqueOnly&quot;, &quot;sourceIn&quot;, &quot;sourceOut&quot;, &quot;sourceAtop&quot;, &quot;destinationOver&quot;, &quot;destinationIn&quot;, &quot;destinationOut&quot;, &quot;destinationAtop&quot;, &quot;xor&quot;, &quot;plusDarker&quot;, &quot;plusLighter&quot;, &quot;divide&quot;, &quot;linearBurn&quot;, &quot;linearDodge&quot;, &quot;lighterColor&quot;, &quot;darkerColor&quot;, &quot;subtract&quot;, &quot;hardmix&quot;, &quot;mask&quot;, &quot;pinLight&quot;, &quot;vividLight&quot;, &quot;linearLight&quot;

| Parameter | Type | Description |
| --- | --- | --- |
| `blendString` | `String` | A string representing the blend (composite) mode. |

```javascript
var layer = acorn.currentDocument().currentLayer();
layer.setBlendMode('linearDodge');
```

<a id="layer-setlayermaskimage"></a>

### `layer.setLayerMaskImage(image)`

Sets the layer mask from a CIImage, creating a mask if needed.

| Parameter | Type | Description |
| --- | --- | --- |
| `image` | `CIImage` | The image to use for the mask. |

```javascript
var layer = acorn.currentDocument().currentLayer();
var maskImage = CIImage.imageWithContentsOfURL(NSURL.fileURLWithPath("/tmp/mask.png"));
layer.setLayerMaskImage(maskImage);
```

<a id="layer-setlayermaskwithimageatpath"></a>

### `layer.setLayerMaskWithImageAtPath(path)`

Sets the layer mask from an image file path, creating a mask if needed.

| Parameter | Type | Description |
| --- | --- | --- |
| `path` | `String` | Path to the mask image. |

```javascript
var layer = acorn.currentDocument().currentLayer();
layer.setLayerMaskWithImageAtPath("/tmp/mask.png");
```

<a id="layer-setlayermaskwithimageaturl"></a>

### `layer.setLayerMaskWithImageAtURL(url)`

Sets the layer mask from an image URL, creating a mask if needed.

| Parameter | Type | Description |
| --- | --- | --- |
| `url` | `NSURL` | URL for the mask image. |

```javascript
var layer = acorn.currentDocument().currentLayer();
var url = NSURL.fileURLWithPath("/tmp/mask.png");
layer.setLayerMaskWithImageAtURL(url);
```

<a id="layer-setmaskislinked"></a>

### `layer.setMaskIsLinked(linked)`

Sets whether the layer mask moves with the layer.

| Parameter | Type | Description |
| --- | --- | --- |
| `linked` | `Boolean` | True to link the mask to the layer. |

```javascript
var layer = acorn.currentDocument().currentLayer();
layer.setMaskIsLinked(false);
```

<a id="layer-visible"></a>

### `layer.visible`

Gets or sets the visibility of a layer.

```javascript
var doc = acorn.currentDocument();
var layer = doc.currentLayer();

// find the current visibility:
var v = layer.visible();
// toggle it
layer.setVisible(!v);
```

<a id="layer-writetofile_withuti_properties"></a>

### `layer.writeToFile_withUTI_properties(path, uti, dict)`

Writes the layer to a file using the given Uniform Type Identifier. Use this method to export or save a single layer.

| Parameter | Type | Description |
| --- | --- | --- |
| `path` | `String` | Destination file path. |
| `uti` | `String` | Uniform Type Identifier for the output format. |
| `properties` | `Dictionary` | A dictionary of image properties. The properties are passed to CGImageDestinationAddImage as the properties dictionary. |

Returns: Boolean True when the write succeeds.

```javascript
var doc = acorn.currentDocument();
var layer = doc.currentLayer();
var properties = {
   [kCGImagePropertyDPIWidth]: 143,
   [kCGImagePropertyDPIHeight]: 143,

   [kCGImagePropertyPNGDictionary]: {
     [kCGImagePropertyPNGSoftware]: "It’s Acorn of course."
   }
}
layer.writeToFile_withUTI_properties("/tmp/export.png", "public.png", properties);
```

## Shape Layer

Shape layers are an extension of the [Layer](#layer) object, and contain vector graphics (aka - Graphic objects)

<a id="shapelayer-addbezierpath"></a>

### `shapeLayer.addBezierPath(path)`

Adds a Bezier path graphic to the shape layer.

| Parameter | Type | Description |
| --- | --- | --- |
| `path` | `NSBezierPath` | Path to add as a shape. |

Returns: BezierGraphic The new Bezier graphic.

```javascript
var path = NSBezierPath.bezierPathWithRect(NSMakeRect(25, 25, 100, 75));
var shapeLayer = acorn.currentDocument().baseGroup().addShapeLayer();
shapeLayer.addBezierPath(path);
```

<a id="shapelayer-addovalwithbounds"></a>

### `shapeLayer.addOvalWithBounds(bounds)`

Adds an oval graphic to the shape layer.

| Parameter | Type | Description |
| --- | --- | --- |
| `bounds` | `NSRect` | Oval bounds in canvas coordinates. |

Returns: Graphic The new oval graphic.

```javascript
var shapeLayer = acorn.currentDocument().baseGroup().addShapeLayer();
var oval = shapeLayer.addOvalWithBounds(NSMakeRect(25, 25, 100, 75));
print(oval.bounds());
```

<a id="shapelayer-addrectanglewithbounds"></a>

### `shapeLayer.addRectangleWithBounds(bounds)`

Adds a rectangle graphic to the shape layer.

| Parameter | Type | Description |
| --- | --- | --- |
| `bounds` | `NSRect` | Rectangle bounds in canvas coordinates. |

Returns: Graphic The new rectangle graphic.

```javascript
var shapeLayer = acorn.currentDocument().baseGroup().addShapeLayer();
var rect = shapeLayer.addRectangleWithBounds(NSMakeRect(25, 25, 100, 75));
print(rect.bounds());
```

<a id="shapelayer-addtextwithbounds"></a>

### `shapeLayer.addTextWithBounds(bounds)`

Adds a text graphic to the shape layer.

| Parameter | Type | Description |
| --- | --- | --- |
| `bounds` | `NSRect` | Text bounds in canvas coordinates. |

Returns: TextGraphic The new text graphic.

```javascript
var shapeLayer = acorn.currentDocument().baseGroup().addShapeLayer();
var text = shapeLayer.addTextWithBounds(NSMakeRect(25, 25, 200, 80));

// Set plain text
// text.setString("Hello from JavaScript");

// Set HTML
text.setHTMLString('<span style="font-size: 40px; font-weight: bold">Hello!</span><br/> <i>from JavaScript</i>');
```

<a id="shapelayer-graphics"></a>

### `shapeLayer.graphics()`

Returns the vector graphics contained by a shape layer. This method will work on a base layer object, but it is only on shape layers that the array will be filled with anything.

Returns: NSArray The layer graphics.

```javascript
var layer = acorn.currentDocument().currentLayer();
var graphics = layer.graphics();
for (var i = 0; i < graphics.count(); i++) {
    print(graphics[i].bounds());
}
```

<a id="shapelayer-movegraphic_toindex"></a>

### `shapeLayer.moveGraphic_toIndex(graphic, index)`

Moves a graphic to a new index in the shape layer.

| Parameter | Type | Description |
| --- | --- | --- |
| `graphic` | `Graphic` | The graphic to move. |
| `index` | `Number` | The destination index. |

```javascript
 // Move the last object to the front
var layer = acorn.currentDocument().currentLayer();
var graphic = layer.graphics().lastObject();
layer.moveGraphic_toIndex(graphic, 0);
```

<a id="shapelayer-selectedgraphics"></a>

### `shapeLayer.selectedGraphics()`

Returns the selected graphics on a shape layer.

Returns: NSArray The selected graphics.

```javascript
var layer = acorn.currentDocument().currentLayer();
var selected = layer.selectedGraphics();
print(selected.count());
```

## Tool Palette

Methods for reading and changing the current tool palette colors. You can get the current tool palette by calling `acorn.toolPalette()`. Note - an image must be open for it to return a value, as each document has its own palette. (In the past there was a single global palette, but that is no more… for the most part).

<a id="toolpalette-backcolor"></a>

### `toolPalette.backColor()`

Returns the current back color.

Returns: NSColor The back color.

```javascript
var palette = acorn.toolPalette();
print(palette.backColor());
```

<a id="toolpalette-frontcolor"></a>

### `toolPalette.frontColor()`

Returns the current front color.

Returns: NSColor The front color.

```javascript
var palette = acorn.toolPalette();
print(palette.frontColor());
```

<a id="toolpalette-setbackcolor"></a>

### `toolPalette.setBackColor(color)`

Sets the current back color.

| Parameter | Type | Description |
| --- | --- | --- |
| `color` | `NSColor` | The new back color. |

```javascript
var palette = acorn.toolPalette();
palette.setBackColor(NSColor.whiteColor());
```

<a id="toolpalette-setfrontcolor"></a>

### `toolPalette.setFrontColor(color)`

Sets the current front color.

| Parameter | Type | Description |
| --- | --- | --- |
| `color` | `NSColor` | The new front color. |

```javascript
var palette = acorn.toolPalette();
palette.setFrontColor(NSColor.blueColor());
```

<%-- AUTODOC_END --%>


