Maya - Callbacks
If you need to install callbacks for export events, the best place to do it is in the initializePlugin()
function of your plug-in. However, as previously discussed, the Maxwell plug-in may not have been loaded yet, so you cannot do it by calling an API method. Maya user messages have the same problem, since Maxwell would have to register a message before you could subscribe to it. This is why we've used MEL for the callback system instead of C++ function pointers.
The callback information is stored in a global MEL string array called g_maxwellExportCallbacks
. It doesn't matter who creates this variable, if it's Maxwell or your plug-in. Maxwell will just look for it at export time and call the commands as necessary. The strings stored in this array have a special format:
plug-in name:type:language:command
The plug-in name is needed to distinguish between callbacks registered by different plug-ins. This is a string you provide when you register the callback, so it's recommended (but not enforced) to use the name of your plug-in here. The type field is a numeric value corresponding to the MaxwellMayaAPI::ExportCallbackType
enum. You should only have one callback of each type for a given plug-in name. The language field is an integer corresponding to the MaxwellMayaAPI::ExportCallbackLanguage
enum and specifies if the callback command is MEL or Python. The final field is the command string which is executed by the Maxwell plug-in.
Managing this variable correctly can be tedious, so MaxwellMayaAPI
provides a few static inline methods for it: SetExportCallback
, RemoveExportCallback
and RemoveExportCallbacks
. These can be called without loading the API. If you do not need these methods and do not want them declared, you can define the MAXWELL_MAYA_NO_CALLBACK_HELPERS
macro before including MaxwellMayaAPI.h
.