AL_USDMaya  0.29.4
USD to Maya Bridge
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Maya Event System

Maya Event System

As a direct replacement to MMessage (and related classes) the class AL::maya::MayaEventManager provides an interface to register your own C++ callback functions. All of the static methods AL::maya::MayaEventManager::registerCallback take the following arguments:

The list of registered event names can be queried by running the mel command:

print `AL_usdmaya_ListEvents`;

The following table lists the registered event name, and the type of callback function required to handle that callback.

example code

A quick example of replacing a MSceneMessage::kAfterNew message with the events system

#include <maya/MFnPlugin.h>
#include "AL/maya/event/MayaEventManager.h"
#include <iostream>
void onFileNewCallback()
{
std::cout << "onFileNewCallback Callback called!" << std::endl;
}
AL::maya::CallbackId g_callback = 0;
MStatus initialisePlugin(MObject obj)
{
MFnPlugin fn(obj);
// the params are:
//
// * the callback function pointer
// * the name of the event
// * A unique tag to identify your callback
// * the callback weight
// * a custom userdata pointer
//
g_callback = AL::maya::event::MayaEventManager::registerCallback(
onFileNewCallback,
"AfterNew",
"MyPlugin_MyCallback",
99999,
nullptr);
return MS::kSuccess;
}
MStatus uninitialisePlugin(MObject obj)
{
MFnPlugin fn(obj);
// and to unregister the callback
AL::maya::event::MayaEventManager::registerCallback(g_callback);
return MS::kSuccess;
}