Cinema 4D communicates with a loaded plugin (cdl64
or dylib
file) by calling three basic functions that have to be implemented by that plugin. Typically these functions are implemented in the plugin's main.cpp
file.
Several messages are sent to PluginMessage(). The order in which these messages are sent and the order in which the functions are called is the following:
Startup:
Events during runtime:
Shutdown:
For the full list of messages see C4DPL_MESSAGES.
PluginStart() will be called after Cinema 4D loaded the plugin. Typically custom plugin classes are installed here using the corresponding "Register" function. PluginStart() may also be the right place to start a background thread or to check the validity of a keyfile.
PluginMessage() receives various messages during startup, shutdown and while Cinema 4D is running.
It is possible to send a custom message to PluginMessage() of all loaded plugins with:
The PluginStart() and PluginEnd() functions of all plugins are called one after another. The plugin priority defines the order in which these functions are called. This is useful to make sure that a given plugin is called before or after a certain other plugin. For most plugins this is typically not needed.
The priority is set using this macro:
The priorities are:
If a plugin uses any resource files in its "res" folder, these resources have to be loaded when Cinema 4D starts. This is done using GeResource::Init().
As this is one of the earliest message, this is the best time to register custom data types and SNHook plugins. This message is not sent to Python plugins.
After the C4DPL_INIT_SYS message, PluginStart() will be called.
During startup the following messages are sent:
Before Cinema 4D finishes its start (C4DPL_PROGRAM_STARTED) it is possible to modify its menus to add new menu entries.
The command line arguments used to start Cinema 4D can be parsed after the application has started.
The data of the message is C4DPL_CommandLineArgs:
When a device is added to or removed from the machine, a plugin message is sent.
The data of the message is C4DPL_DeviceChange:
The following messages are sent during Cinema 4D's shutdown.
PluginEnd() is called before a plugin is unloaded and is the last opportunity to free resources. Here low level cleanup should be done e.g. for Strings and Filenames. Also imported DLLs should be unloaded here.