//- // ========================================================================== // Copyright (C) 1995 - 2006 Autodesk, Inc. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files contain unpublished // information proprietary to Autodesk, Inc. ("Autodesk") and/or its // licensors, which is protected by U.S. and Canadian federal copyright // law and by international treaties. // // The Data is provided for use exclusively by You. You have the right // to use, modify, and incorporate this Data into other products for // purposes authorized by the Autodesk software license agreement, // without fee. // // The copyright notices in the Software and this entire statement, // including the above license grant, this restriction and the // following disclaimer, must be included in all copies of the // Software, in whole or in part, and all derivative works of // the Software, unless such copies or derivative works are solely // in the form of machine-executable object code generated by a // source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. // AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED // WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF // NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR // PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR // TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS // BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL, // DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK // AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY // OR PROBABILITY OF SUCH DAMAGES. // // ========================================================================== //+ /* 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, 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; }