instanceCallbackCmd.cpp
#include <maya/MFnPlugin.h>
#include <maya/MPxCommand.h>
#include <maya/MArgList.h>
#include <maya/MItDependencyNodes.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MString.h>
#include <maya/MGlobal.h>
#include <maya/MLockMessage.h>
#include <maya/MFnAttribute.h>
#include <maya/MFnMesh.h>
#include <maya/MFloatPointArray.h>
#include <maya/MIntArray.h>
#include <maya/MDagPath.h>
#include <maya/MDagMessage.h>
#include <maya/MFnNurbsCurve.h>
void addCallbackFunc (MDagPath &dagPath, MDagPath &otherPath,
void *clientData )
{
MGlobal::displayInfo("CALLBACK-FUNCTION REGISTERED FOR INSTANCE ADDED INVOKED");
}
void remCallbackFunc ( MDagPath &dagPath, MDagPath &otherPath, void *clientData)
{
MGlobal::displayInfo("CALLBACK-FUNCTION REGISTERED FOR INSTANCE REMOVED INVOKED");
}
class InstanceCallbackCmd : public MPxCommand
{
public:
MStatus doIt( const MArgList& args );
static void* creator();
};
void* InstanceCallbackCmd::creator()
{
return new InstanceCallbackCmd;
}
MStatus InstanceCallbackCmd::doIt( const MArgList& args )
{
MStatus status = MS::kSuccess;
MGlobal::executeCommand("circle");
MFnNurbsCurve circle;
MDagPath dagPath;
MItDependencyNodes iter( MFn::kNurbsCurve , &status);
for(iter.reset(); !iter.isDone() ; iter.next())
{
MObject item = iter.item();
if(item.hasFn(MFn::kNurbsCurve))
{
circle.setObject(item);
circle.getPath(dagPath);
MGlobal::displayInfo("DAG_PATH is " + dagPath.fullPathName());
if(dagPath.isValid())
{
MDagMessage::addInstanceAddedCallback ( dagPath,addCallbackFunc, NULL, &status);
MDagMessage::addInstanceRemovedCallback ( dagPath,remCallbackFunc, NULL, &status);
MGlobal::displayInfo("CALLBACK ADDED FOR INSTANCE ADD/REMOVE");
}
}
}
if (status != MS::kSuccess)
{
MGlobal::displayInfo("STATUS RETURNED IS NOT SUCCESS");
}
return status;
}
MStatus initializePlugin( MObject obj )
{
MStatus status;
MFnPlugin plugin( obj, PLUGIN_COMPANY, "6.0", "Any");
plugin.registerCommand( "instCallbackCmd", InstanceCallbackCmd::creator);
MGlobal::displayInfo("PLUGIN LOADED");
return status;
}
MStatus uninitializePlugin( MObject obj )
{
MStatus status;
MFnPlugin plugin( obj );
plugin.deregisterCommand( "instCallbackCmd" );
return status;
}