
21
2
Tutorial
This chapter describes the fundamentals of Illustrator plug-in programming, using as an example a plug-in
called Tutorial that is provided on the SDK. Look for the sample project in the sample code folder on the
SDK, and browse the source code while reading this chapter.
The core characteristics of an Illustrator plug-in were introduced in
Chapter 1, “Overview
. If you have not
read that chapter already, do so before proceeding through this chapter.
PiPL resource and plug-in entry point
Illustrator plug-ins must have a valid PiPL resource and an entry point Illustrator can call.
The Tutorial plug-in’s PiPL resource declaration is in the following source files:
X
Windows:
Tutorial.rc
X
Mac OS:
Tutorial.r
For more information on PiPLs, see
“Plug–in Property Lists” on page 35
.
The Tutorial plug-in’s entry point is the
PluginMain
function in
Tutorial.cpp
.
Only plug-ins with the Illustrator version information in the PiPL are recognized and included in
Illustrator’s initial start-up process. A plug-in is loaded into and unloaded from memory as needed by
Illustrator. Your plug-in should be written assuming it is not always in memory. This is why your plug-in
should save and restore state information during unload and reload. Your plug-in can expect certain
services from the application. Because your plug-in may be unloaded, Illustrator provides a means of
storing important data when the plug-in is unloaded. Each time the plug-in is called, it is given enough
information to accomplish the action to be performed.
Handling callers and selectors
Your plug-in’s organization is based largely on the messages received by its
PluginMain
function. The
main routine of your plug-in basically becomes a switch implemented as a series of string comparisons
that call functions appropriate for the message action caller and selector. See
“Handling callers and
selectors” on page 14
.
Using suites and callback functions
The Illustrator API provides the core functionality used by a plug-in. Illustrator’s API comprises callback
functions organized into suites. Before your plug-in can use a function that is part of a suite, the suite
containing it must first be
acquired
. A suite is a structure filled with function pointers; when your plug-in
acquires a suite, a pointer to this structure is returned.
When the suite is no longer needed, the acquired suite is
released
. It is important to do this, so the
Illustrator plug-in manager can run optimally. For instance, Illustrator keeps track of how many times a
suite was acquired. If a suite added by plug-in is no longer in use (its reference count is 0), the plug-in may
be unloaded to free memory.