Before we start, let's define what we mean when we talk about items. An item is anything that appears in your document: layers, paths, groups, text items, images etc.
Every kind of item has specific behaviours: a path contains points, a layer can be active, groups and compound paths have children.
But since they are all items, they also share a number of behaviours. All these shared behaviours can be found in the Item reference.
An item can be selected, locked, visible or hidden (or a combination of these):
For example if we would want to make a path item and have it be selected:
var circlePath = new Path.Circle(new Point(50, 50), 25); circlePath.selected = true;
Items can also be named in the layers palette by passing a string to its item.name property:
var circlePath = new Path.Circle(new Point(50, 50), 25); circlePath.name = 'Circletastic';
You can give items a blend mode and make them transparent:
For example, we could make a half transparent path by setting the item.opacity property of it to a value between 0 and 1:
var circlePath = new Path.Circle(new Point(50, 50), 25); circlePath.opacity = 0.5;
To change the blend mode of an item we pass a string to its item.blendMode property:
var circlePath = new Path.Circle(new Point(50, 50), 25); circlePath.blendMode = 'multiply';
Visit the item.blendMode reference to see the different supported blend modes.
When you want to remove an item in Illustrator, you select it and then press the delete key. To remove an item using Scriptographer you call the item.remove() function.
For example let's create a path and remove it straight away. When you execute the following code, nothing will appear in your document, since the we remove the path right after creating it.
var circlePath = new Path.Circle(new Point(50, 50), 25); circlePath.remove();
To make copies of an item in Illustrator, you need to select it, copy it and paste it. To make a copy of an item using Scriptographer, you call its item.clone() function. The item.clone() function returns the cloned path, so we need to store it in a variable if we want to do something with the copy.
The following example create a circle shaped path, clones it and then changes a couple of properties of the clone.
var circlePath = new Path.Circle(new Point(50, 50), 25); // clone the path and store it in a variable var clonedPath = circlePath.clone(); // move the cloned path 50pt to the right: clonedPath.position += new Point(50, 0); // select the cloned path clonedPath.selected = true;