#include <maya/MIOStream.h>
#include <maya/MPxCommand.h>
#include <maya/MFnPlugin.h>
#include <maya/MArgList.h>
#include <maya/MArgDatabase.h>
#include <maya/MIntArray.h>
#include <maya/MSelectionList.h>
#include <maya/MGlobal.h>
#include <maya/MPlug.h>
#include <maya/MSyntax.h>
#include <maya/MDagMessage.h>
#include <maya/MDGMessage.h>
#include <maya/MModelMessage.h>
#include <maya/MDagPath.h>
#include <maya/MFnDagNode.h>
#include <maya/MCallbackIdArray.h>
#include <maya/MObjectArray.h>
#define kCmdName "dagMessage"
#define kAllDagFlag "-ad"
#define kAllDagFlagLong "-allDag"
#define kParentAddedFlag "-pa"
#define kParentAddedFlagLong "-parentAdded"
#define kParentRemovedFlag "-pr"
#define kParentRemovedFlagLong "-parentRemoved"
#define kChildAddedFlag "-ca"
#define kChildAddedFlagLong "-childAdded"
#define kChildRemovedFlag "-cr"
#define kChildRemovedFlagLong "-childRemoved"
#define kChildReorderedFlag "-cro"
#define kChildReorderedFlagLong "-childReordered"
#define kHelpFlag "-h"
#define kHelpFlagLong "-help"
#define CheckErrorContinue(stat, msg) \
if (MS::kSuccess != stat) { \
displayError(msg); \
continue; \
}
#define CheckErrorReturn(stat, msg) \
if (MS::kSuccess != stat) { \
displayError(msg); \
return; \
}
static void userNodeRemovedCB(
MObject& node,
void *clientData)
{
bool doDisplay = true;
doDisplay = false;
}
if ( doDisplay ) {
MString info(
"DAG Model - Node removed: ");
info+= s;
}
}
}
static void userNodeAddedCB(
MObject& node,
void *clientData)
{
bool doDisplay = true;
doDisplay = false;
}
if ( doDisplay ) {
MString info(
"DAG Model - Node added: ");
info+= s;
info += "(WORLD)";
}
}
}
return;
}
}
static void installNodeAddedCallback(
MDagPath& dagPath )
{
return;
return;
}
}
static bool dagNotInModel(
MDagPath& dagPath )
{
return false;
bool inModel = dagFn.inModel( &status );
return false;
return ( inModel == false );
}
{
switch (msg) {
dagStr += "Parent Added: ";
break;
dagStr += "Parent Removed: ";
break;
dagStr += "Child Added: ";
break;
dagStr += "Child Removed: ";
break;
dagStr += "Child Reordered: ";
break;
default:
dagStr += "Unknown Type: ";
break;
}
dagStr += "child = ";
dagStr += ", parent = ";
dagStr += "(WORLD)";
}
bool incomplete = false;
if ( dagNotInModel( child ) ) {
installNodeAddedCallback( child );
incomplete = true;
}
if ( dagNotInModel( parent ) ) {
installNodeAddedCallback( parent);
incomplete = true;
}
if (incomplete)
dagStr += "\t// May be incomplete!";
}
{
public:
dagMessageCmd() {};
virtual ~dagMessageCmd();
static void* creator();
private:
};
dagMessageCmd::~dagMessageCmd() {}
void* dagMessageCmd::creator()
{
return new dagMessageCmd();
}
{
syntax.
addFlag(kAllDagFlag, kAllDagFlagLong);
syntax.
addFlag(kParentAddedFlag, kParentAddedFlagLong);
syntax.
addFlag(kParentRemovedFlag, kParentRemovedFlagLong);
syntax.
addFlag(kChildAddedFlag, kChildAddedFlagLong);
syntax.
addFlag(kChildRemovedFlag, kChildRemovedFlagLong);
syntax.
addFlag(kChildReorderedFlag, kChildReorderedFlagLong);
syntax.
addFlag(kHelpFlag, kHelpFlagLong);
return syntax;
}
{
if (NULL == dagPath) {
userDAGGenericCB,
NULL,
&status);
MString info(
"Adding a callback for");
info += cbName;
info += "on all nodes";
} else {
MString err(
"Could not add callback to");
}
} else {
msg,
userDAGGenericCB,
NULL,
&status);
MString info(
"Adding a callback for");
info += cbName;
info += "on ";
} else {
MString err(
"Could not add callback to");
}
}
return status;
}
{
status = argData.getObjects(list);
return status;
}
bool allDagUsed = argData.isFlagSet(kAllDagFlag);
bool parentAddedUsed = argData.isFlagSet(kParentAddedFlag);
bool parentRemovedUsed = argData.isFlagSet(kParentRemovedFlag);
bool childAddedUsed = argData.isFlagSet(kChildAddedFlag);
bool childRemovedUsed = argData.isFlagSet(kChildRemovedFlag);
bool childReorderedUsed = argData.isFlagSet(kChildReorderedFlag);
bool helpUsed = argData.isFlagSet(kHelpFlag);
bool nothingSet = ( !allDagUsed && !parentAddedUsed &&
!parentRemovedUsed && !childAddedUsed &&
!childRemovedUsed && !childReorderedUsed &&
!helpUsed);
if (nothingSet) {
}
if (argData.isFlagSet(kHelpFlag)) {
}
unsigned nObjs = list.
length();
if (nObjs == 0) {
if (allDagUsed) {
if (status) {
} else {
return status;
}
}
if (parentAddedUsed) {
status = addGenericCallback(NULL,
return status;
}
}
if (parentRemovedUsed) {
status = addGenericCallback(NULL,
return status;
}
}
if (childAddedUsed) {
return status;
}
if (childRemovedUsed) {
return status;
}
if (childReorderedUsed) {
status = addGenericCallback(NULL,
return status;
}
}
} else {
for (unsigned int i=0; i< nObjs; i++) {
continue;
}
if (allDagUsed) {
if (status) {
MString infoStr(
"Added a callback for all Dag changes on ");
} else {
return status;
}
}
if (parentAddedUsed) {
status = addGenericCallback(&dagPath,
return status;
}
}
if (parentRemovedUsed) {
status = addGenericCallback(&dagPath,
return status;
}
}
if (childAddedUsed) {
status = addGenericCallback(&dagPath,
return status;
}
}
if (childRemovedUsed) {
status = addGenericCallback(&dagPath,
return status;
}
}
if (childReorderedUsed) {
status = addGenericCallback(&dagPath,
return status;
}
}
}
}
return status;
}
{
return plugin.registerCommand( kCmdName,
dagMessageCmd::creator,
dagMessageCmd::newSyntax);
}
{
for (
unsigned int i=0; i<callbackIds.
length(); i++ ) {
}
return plugin.deregisterCommand( kCmdName );
}