//- // ========================================================================== // Copyright (C) 1995 - 2005 Alias Systems Corp. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files are provided by Alias // Systems Corp. ("Alias") and/or its licensors for the exclusive use of the // Customer (as defined in the Alias Software License Agreement that // accompanies this Alias software). Such Customer has the right to use, // modify, and incorporate the Data into other products and to distribute such // products for use by end-users. // // THE DATA IS PROVIDED "AS IS". ALIAS HEREBY DISCLAIMS ALL WARRANTIES // RELATING TO THE DATA, INCLUDING, WITHOUT LIMITATION, ANY AND ALL EXPRESS OR // IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. IN NO EVENT SHALL ALIAS BE LIABLE FOR ANY DAMAGES // WHATSOEVER, WHETHER DIRECT, INDIRECT, SPECIAL, OR PUNITIVE, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, OR IN EQUITY, // ARISING OUT OF ACCESS TO, USE OF, OR RELIANCE UPON THE DATA. // ========================================================================== //+ /* File: instanceCallbackCmd.cpp Command: "instCallbackCmd" Description class InstanceCallbackCmd This plugin demonstrates the functionality added to MDagMessage class. The new functions added allow callbacks to be added for 1) Instance Added for a specified node(and its instances) 2) Instance Removed for a specified node(and its instances) 3) Instance Added for any node 4) Instance Removed for any node This plugin: i. Draws a circle, ii. Gets its dagPath using an iterator iii. Adds callback for instance added and removed for this circle. The callback functions just displays a message indicating the invocation of the registered callback function. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // callback function for instance added void addCallbackFunc (MDagPath &dagPath, MDagPath &otherPath, void *clientData/*, MLockMessage::LockDAGEvent eventType, bool &decision*/ ) { MGlobal::displayInfo("CALLBACK-FUNCTION REGISTERED FOR INSTANCE ADDED INVOKED"); } // callback function for instance removed 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; // Draw a circle and get its dagPath // using an iterator 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()) { // register callback for instance add AND remove // 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; } //////////////////////////////////////////////////////////////// // // Init // UnInit // //////////////////////////////////////////////////////////////// MStatus initializePlugin( MObject obj ) { MStatus status; MFnPlugin plugin( obj, "Alias", "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; }