The Tool object refers to the Scriptographer tool in the Illustrator tool palette and can be accessed through the global tool variable. All its properties are also available in the global scope.
The global tool variable only exists in scripts that contain mouse handler functions (onMouseDown, onMouseDrag, onMouseUp), which are automatically associated with the tool button on execution.
Sample code:
var path;
// Only execute onMouseDrag when the mouse
// has moved at least 10 points:
tool.distanceThreshold = 10;
function onMouseDown(event) {
// Create a new path every time the mouse is clicked
path = new Path();
}
function onMouseDrag(event) {
// Add a point to the path every time the mouse is dragged
path.lineTo(event.point);
}
Properties
Sets the fixed time delay between each call to the onMouseDrag event. Setting this to an interval means the onMouseDrag event is called repeatedly after the initial onMouseDown until the user releases the mouse.
Sample code:
// Fire the onMouseDrag event once a second, // while the mouse button is down tool.eventInterval = 1000;
- Returns:
- Number — the interval time in milliseconds
Tool Button Styling
- Returns:
- Image
The minimum distance the mouse has to drag before firing the onMouseDrag event, since the last onMouseDrag event.
Sample code:
// Fire the onMouseDrag event after the user has dragged // more then 5 points from the last onMouseDrag event: tool.minDistance = 5;
- Returns:
- Number
- Returns:
- Number
- Returns:
- Number
Mouse Event Handlers
The function to be called when the mouse button is pushed down. The function receives a ToolEvent object which contains information about the mouse event.
Sample code:
function onMouseDown(event) {
// the position of the mouse in document coordinates:
print(event.point);
}
- Returns:
- Function
The function to be called when the mouse position changes while the mouse is being dragged. The function receives a ToolEvent object which contains information about the mouse event.
This function can also be called periodically while the mouse doesn't move by setting the eventInterval
Sample code:
function onMouseDrag(event) {
// the position of the mouse in document coordinates
print(event.point);
}
- Returns:
- Function
The function to be called when the tool is selected and the mouse moves within the document. The function receives a ToolEvent object which contains information about the mouse event.
Sample code:
function onMouseMove(event) {
// the position of the mouse in document coordinates
print(event.point);
}
- Returns:
- Function
Tool Button Event Handlers
The function to be called when the tool button is double clicked. This is often used to present the users with a dialog containing options that they can set.
- Returns:
- Function
The function to be called when the tool button is deselected.
- Returns:
- Function
The function to be called when the tool button has been reselected.
- Returns:
- Function
Functions
Checks whether the input device of the user has a pressure feature (i.e. a drawing tablet)
- Returns:
- Boolean
- Parameters:
- type: String ('mousedown', 'mouseup', 'mousedrag', 'mousemove', 'edit-options', 'select', 'deselect', 'reselect', 'decrease-diameter', 'increase-diameter')
- pt: Point
- pressure: Number — optional
- modifiers: Number — optional