C
HAPTER
2: Tutorial
Plug-in type-specific messages
27
else if ( strcmp( caller, kCallerAITool ) == 0 ) {
if ( strcmp( selector, kSelectorAIToolMouseDown ) == 0 )
error = ToolMouseDown( ( AIToolMessage* )message );
}
When the mouse is clicked, the Tutorial plug-in receives this selector and can process it. See the
ToolMouseDown
function in
Tutorial.cpp
. This function draws path segments to each mouse-down
location. The location of the mouse is passed in the tool-message structure; see
AIToolMessage
in
Adobe
Illustrator API Reference
. The tool message contains the basic plug-in data and a reference to the tool being
used. The
cursor
field contains the point on the art board where the last tool event occurred, and the
Tutorial plug-in’s mouse-down handler uses this to create a path. The
ToolMouseDown
function begins by
acquiring the suites it needs to make a line. The function checks whether a selected path exists. If so, it
adds path segments to it; otherwise, it creates the first point in a new path. The function ends by releasing
the suites it acquired.
While the
ToolMouseDown
function adds a basic tool, other selectors can be processed to give the line tool
more functionality, like setting the cursor or tracking a mouse drag. This is left as an exercise for the reader.
Action plug-ins
For your plug-in to be recordable by Illustrator’s Actions panel, you must add special code to your plug-in.
Follow these steps:
1.
Register action events
— During start-up, your plug-in must register one or more action events. An
action event is a single operation your plug-in executes. An Action event is shown in Illustrator’s
Actions panel, if the user chooses to record it.
2.
Record action events
— During your plug-in’s execution, you must check whether the user is in
record mode. If so, you must record your action event and pass all relevant parameters to the Action
Manager.
3.
Respond to the DoAction selector
— Once you register one or more Action Events, your plug-in
must be ready to execute those Action Events when requested. Your plug-in must respond to the
kActionCaller
caller and
kDoActionSelector
selector. These are defined in the Action Manager
suite header file.
Registering action events
First, determine how many action events your plug-in will register, by separating the functionality of your
plug-in into discrete operations. Basically, try to think of which operations users will want to record in the
Actions panel.
During start-up, your plug-in should first make sure the Action Manager suite (see
AIActionManagerSuite
) is available, by trying to acquire a pointer to the suite. This check is necessary
because the Action Plug-in may be disabled by removing it from the
Plug-ins
folder.
To register an action event, your plug-in must do the following:
X
Call
AIActionManagerSuite::AINewActionParamType
to create a type parameter block (TPB) that
describes the parameters your action event requires.
X
Populate the TPB with key-value pairs that give the name and data type of each parameter by calling
AIActionManagerSuite::
AIActionSetTypeKey
.
X
Call
AIActionManagerSuite::
RegisterActionEvent
to register the action event.