The Item type allows you to access and modify the artwork items in Illustrator documents. Its functionality is inherited by different document item types such as Path, CompoundPath, Group, Layer and Raster. They each add a layer of functionality that is unique to their type, but share the underlying properties and functions that they inherit from Item.
Properties
The name of the item as it appears in the layers palette.
Sample code:
var layer = new Layer(); // a layer is an item print(layer.name); // null layer.name = 'A nice name'; print(layer.name); // 'A nice name'
- Returns:
- String
The item's position within the art board. This is the rectangle.center of the bounds rectangle.
Sample code:
// Create a circle at position { x: 10, y: 10 } var circle = new Path.Circle(new Point(10, 10), 10); // Move the circle to { x: 20, y: 20 } circle.position = new Point(20, 20); // Move the circle 10 points to the right circle.position += new Point(10, 0); print(circle.position); // { x: 30, y: 20 }
- Returns:
- Point
Specifies whether an item is selected.
Sample code:
print(document.selectedItems.length); // 0 var path = new Path.Circle(new Size(50, 50), 25); path.selected = true; // Select the path print(document.selectedItems.length) // 1
- Returns:
- Boolean — {true if the item is selected or partially selected (groups with some selected items/partially selected paths)}
Specifies whether the item is fully selected. For paths this means that all segments are selected, for container items (groups/layers) all children are selected.
- Returns:
- Boolean — true if the item is fully selected, false otherwise
Specifies whether the item is locked.
Sample code:
var path = new Path(); print(path.locked) // false path.locked = true; // Locks the path
- Returns:
- Boolean — true if the item is locked, false otherwise
Specifies whether the item is visible.
Sample code:
var path = new Path(); print(path.visible) // true path.visible = false; // Hides the path
- Returns:
- Boolean — true if the item is visible, false otherwise
Specifies whether the item defines a clip mask. This can only be set on paths, compound paths, and text frame objects, and only if the item is already contained within a clipping group.
Sample code:
var group = new Group(); group.appendChild(path); group.clipped = true; path.clipMask = true;
- Returns:
- Boolean — true if the item defines a clip mask, false otherwise
Specifies whether the item is targeted.
Sample code:
var path = new Path(); print(path.targeted) // false path.targeted = true; // Marks the the path as targeted
- Returns:
- Boolean — true if the item is locked, false otherwise
The blend mode of the item.
Sample code:
var circle = new Path.Circle(new Point(50, 50), 10); print(circle.blendMode); // normal // Change the blend mode of the path item: circle.blendMode = 'multiply';
- Returns:
- String ('normal', 'multiply', 'screen', 'overlay', 'soft-light', 'hard-light', 'color-dodge', 'color-burn', 'darken', 'lighten', 'difference', 'exclusion', 'hue', 'saturation', 'color', 'luminosity')
The opacity of the item.
Sample code:
// Create a circle at position { x: 10, y: 10 } var circle = new Path.Circle(new Point(10, 10), 10); // Change the opacity of the circle to 50%: circle.opacity = 0.5;
- Returns:
- Number — the opacity of the item as a value between 0 and 1.
- Returns:
- Boolean
An object contained within the item which can be used to store data. The values in this object can be accessed even after the file has been closed and opened again. Since these values are stored in a native structure, only a limited amount of value types are supported: Number, String, Boolean, Item, Point, Matrix.
Sample code:
var path = new Path.Circle(new Point(50, 50), 50); path.data.point = new Point(50, 50); print(path.data.point); // {x: 50, y: 50}
- Returns:
- Object
Document Hierarchy
The children items contained within this item.
Sample code:
var group = new Group(); // the group doesn't have any children yet print(group.children.length); // 0 var path = new Path(); path.name = 'pathName'; // append the path in the group group.appendTop(path); print(group.children.length); // 1 // access children by index: print(group.children[0]); // Path (pathName) // access children by name: print(group.children['pathName']); // Path (pathName)
- Returns:
- Array of Item, also accessible by name
The first item contained within this item. Read-only.
- Returns:
- Item
The next item on the same level as this item. Read-only.
- Returns:
- Item
The previous item on the same level as this item. Read-only.
- Returns:
- Item
The index of this item within the list of it's parent's children. Read-only.
- Returns:
- Number
Bounding Rectangles
The bounding rectangle of the item including stroke width. Read-only.
- Returns:
- Rectangle
The bounding rectangle of the item including stroke width and controls. Read-only.
- Returns:
- Rectangle
Stroke Style
The color of the stroke.
Sample code:
// Create a circle shaped path at { x: 50, y: 50 } with a radius of 10: var circle = new Path.Circle(new Point(50, 50), 10); // Set the stroke color of the circle to CMYK red: circle.strokeColor = new CMYKColor(1, 1, 0, 0);
- Returns:
- Color
The width of the stroke.
Sample code:
// Create a circle shaped path at { x: 50, y: 50 } with a radius of 10: var circle = new Path.Circle(new Point(50, 50), 10); // Set the stroke width of the circle to 3pt: circle.strokeWidth = 3;
- Returns:
- Number
The cap of the stroke.
Sample code:
// Create a line from { x: 0, y: 50 } to { x: 50, y: 50 }; var line = new Path.Line(new Point(0, 50), new Point(50, 50)); // Set the stroke cap of the line to be round: line.strokeCap = 'round';
- Returns:
- String ('butt', 'round', 'square')
The join of the stroke.
- Returns:
- String ('miter', 'round', 'bevel')
The dash offset of the stroke.
- Returns:
- Number
Specifies an array containing the dash and gap lengths of the stroke.
Sample code:
// Create a line from { x: 0, y: 50 } to { x: 50, y: 50 }; var line = new Path.Line(new Point(0, 50), new Point(50, 50)); line.strokeWidth = 3; // Set the dashed stroke to [10pt dash, 5pt gap, 8pt dash, 10pt gap]: line.dashArray = [10, 5, 8, 10];
- Returns:
- Array of Number
The miter limit controls when the program switches from a mitered (pointed) join to a beveled (squared-off) join. The default miter limit is 4, which means that when the length of the point reaches four times the stroke weight, the program switches from a miter join to a bevel join. A miter limit of 0 results in a bevel join.
- Returns:
- Number
Specifies whether to overprint the stroke. By default, when you print opaque, overlapping colors, the top color knocks out the area underneath. You can use overprinting to prevent knockout and make the topmost overlapping printing ink appear transparent in relation to the underlying ink.
- Returns:
- Boolean
Fill Style
Specifies whether to overprint the fill. By default, when you print opaque, overlapping colors, the top color knocks out the area underneath. You can use overprinting to prevent knockout and make the topmost overlapping printing ink appear transparent in relation to the underlying ink.
- Returns:
- Boolean
Path Style
- Returns:
- String ('even-odd', 'non-zero')
The output resolution for the path.
- Returns:
- Number
Functions
Removes the item from the document. If the item has children, they are also removed.
- Returns:
- Boolean — true if the item was removed, false otherwise
Removes all the children items contained within the item.
- Returns:
- Boolean — true if removing was successful, false otherwise
- Parameters:
- inherited: Boolean
- Returns:
- String ('unknown', 'off', 'on', 'inherit')
Reverses the order of this item's children
- Returns:
- Boolean
- Parameters:
- point: Point
- request: String ('all', 'anchors', 'points', 'end-anchors', 'end-points', 'guides', 'paths', 'text-items', 'texts', 'selection', 'all-except-guides', 'paintables', 'all-except-fills', 'all-except-handles', 'all-except-guides-and-fills', 'all-except-guides-and-locked') — optional
- tolerance: Number — optional
- Returns:
- HitResult
- Parameters:
- flags: Array of String ('plugin-art', 'text', 'stroke', 'pattern', 'gradient-to-mesh', 'gradient-to-paths', 'symbol-instances', 'one-by-one', 'show-progress', 'locked-objects') — optional
- steps: Number — optional
- Returns:
- Item
Rasterizes the item into a newly created Raster object. The item itself is not removed after rasterization.
- Parameters:
- type: String — the color mode of the raster ('rgb', 'cmyk', 'gray', 'bitmap', 'argb', 'acmyk', 'agray', 'abitmap') — optional, default: same as document
- resolution: Number — the resolution of the raster in dpi — optional, default: 72
- antialiasing: Number — the amount of anti-aliasing — optional, default: 4
- width: Number — optional, default: automatic
- height: Number — optional, default: automatic
- Returns:
- Raster — the newly created Raster item
Tests
Checks if the item contains any children items.
- Returns:
- Boolean — true if it has one or more children, false otherwise
Checks whether the item is editable.
- Returns:
- Boolean — true when neither the item, nor it's parents are locked or hidden, false otherwise
Checks whether the item is valid, i.e. it hasn't been removed.
Sample code:
var path = new Path(); print(path.isValid()); // true path.remove(); print(path.isValid()); // false
- Returns:
- Boolean — true if the item is valid, false otherwise
Hierarchy Operations
Inserts the specified item as a child of the item by appending it to the list of children and moving it above all other children. You can use this function for groups, compound paths and layers.
Sample code:
var group = new Group(); var path = new Path(); group.appendTop(path); print(path.isDescendant(group)); // true
- Parameters:
- item: Item — The item that will be appended as a child
- Returns:
- Boolean
Inserts the specified item as a child of this item by appending it to the list of children and moving it below all other children. You can use this function for groups, compound paths and layers.
Sample code:
var group = new Group(); var path = new Path(); group.appendBottom(path); print(path.isDescendant(group)); // true
- Parameters:
- item: Item — The item that will be appended as a child
- Returns:
- Boolean
Moves this item above the specified item.
Sample code:
var firstPath = new Path(); var secondPath = new Path(); print(firstPath.isAbove(secondPath)); // false firstPath.moveAbove(secondPath); print(firstPath.isAbove(secondPath)); // true
- Parameters:
- item: Item — The item above which it should be moved
- Returns:
- Boolean — true if it was moved, false otherwise
Moves the item below the specified item.
Sample code:
var firstPath = new Path(); var secondPath = new Path(); print(secondPath.isBelow(firstPath)); // false secondPath.moveBelow(firstPath); print(secondPath.isBelow(firstPath)); // true
- Parameters:
- item: Item — the item below which it should be moved
- Returns:
- Boolean — true if it was moved, false otherwise
Hierarchy Tests
Checks if this item is above the specified item in the stacking order of the document.
Sample code:
var firstPath = new Path(); var secondPath = new Path(); print(secondPath.isAbove(firstPath)); // true
- Parameters:
- item: Item — The item to check against
- Returns:
- Boolean — true if it is above the specified item, false otherwise
Checks if the item is below the specified item in the stacking order of the document.
Sample code:
var firstPath = new Path(); var secondPath = new Path(); print(firstPath.isBelow(secondPath)); // true
- Parameters:
- item: Item — The item to check against
- Returns:
- Boolean — true if it is below the specified item, false otherwise
- Parameters:
- item: Item
- Returns:
- Boolean
- Parameters:
- item: Item
- Returns:
- Boolean
Checks if the item is contained within the specified item.
Sample code:
var group = new Group(); var path = new Path(); group.appendTop(path); print(path.isDescendant(group)); // true
- Parameters:
- item: Item — The item to check against
- Returns:
- Boolean — true if it is inside the specified item, false otherwise
Checks if the item is an ancestor of the specified item.
Sample code:
var group = new Group(); var path = new Path(); group.appendChild(path); print(group.isAncestor(path)); // true print(path.isAncestor(group)); // false
- Parameters:
- item: Item — the item to check against
- Returns:
- Boolean — true if the item is an ancestor of the specified item, false otherwise
Checks whether the item is grouped with the specified item.
- Parameters:
- item: Item
- Returns:
- Boolean — true if the items are grouped together, false otherwise
Transform Functions
Scales the item by the given values from its center point, or optionally by a supplied point.
- Parameters:
- sx: Number
- sy: Number
- center: Point — optional, default: the center point of the item
See also: matrix.scale(scaleX, scaleY[, center])
Scales the item by the given value from its center point, or optionally by a supplied point.
Sample code:
// Create a circle at position { x: 10, y: 10 } var circle = new Path.Circle(new Point(10, 10), 10); print(circle.bounds.width); // 20 // Scale the path by 200% around its center point circle.scale(2); print(circle.bounds.width); // 40
// Create a circle at position { x: 10, y: 10 } var circle = new Path.Circle(new Point(10, 10), 10); // Scale the path 200% from its bottom left corner circle.scale(2, circle.bounds.bottomLeft);
- Parameters:
- scale: Number — the scale factor
- center: Point — optional, default: the center point of the item
See also: matrix.scale(scale[, center])
Translates (moves) the item by the given offset point.
Sample code:
// Create a circle at position { x: 10, y: 10 } var circle = new Path.Circle(new Point(10, 10), 10); circle.translate(new Point(5, 10)); print(circle.position); // {x: 15, y: 20}Alternatively you can also add to the position of the item:
// Create a circle at position { x: 10, y: 10 } var circle = new Path.Circle(new Point(10, 10), 10); circle.position += new Point(5, 10); print(circle.position); // {x: 15, y: 20}
- Parameters:
- t: Point
Rotates the item by a given angle around the given point.
Angles are oriented clockwise and measured in degrees by default. Read more about angle units and orientation in the description of the point.angle property.
- Parameters:
- angle: Number — the rotation angle
- center: Point — optional
See also: matrix.rotate(angle[, center])
Shears the item with a given amount around its center point.
- Parameters:
- shx: Number
- shy: Number
See also: matrix.shear(shearX, shearY)
Transforms the item with custom flags to be set.
- Parameters:
- matrix: Matrix
- flags: Array of String ('objects', 'fill-gradients', 'fill-patterns', 'stroke-patterns', 'lines', 'linked-masks', 'children', 'selection-only') — optional
Static Functions
Rasterizes the passed items into a newly created Raster object. The items are not removed after rasterization.
- Parameters:
- items: Array of Item
- type: String — the color mode of the raster ('rgb', 'cmyk', 'gray', 'bitmap', 'argb', 'acmyk', 'agray', 'abitmap') — optional, default: same as document
- resolution: Number — the resolution of the raster in dpi — optional, default: 72
- antialiasing: Number — the amount of anti-aliasing — optional, default: 4
- width: Number — optional, default: automatic
- height: Number — optional, default: automatic
- Returns:
- Raster — the newly created Raster item