//- // ========================================================================== // 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. // ========================================================================== //+ // // nodeMessageCmd.cc // // Description: // Sample plug-in that demonstrates how to register/de-register // a callback with the MNodeMessage class. // // This plug-in will register a new command in maya called // "nodeMessage" which adds a callback for the all nodes on // the active selection list. A message is printed to stdout // whenever a connection is made or broken for those nodes. // #include #include #include #include #include #include #include #include #include #include // This table will keep track of the registered callbacks // so they can be removed when the plug-ins is unloaded. // MCallbackIdArray callbackIds; ////////////////////////////////////////////////////////////////////////// // // Callback function // // Prints out plug information when connections are made or broken. // See MNodeMessage.h for all of the available AttributeMessage types. // ////////////////////////////////////////////////////////////////////////// void userCB( MNodeMessage::AttributeMessage msg, MPlug & plug, MPlug & otherPlug, void* ) { if ( msg & MNodeMessage::kConnectionMade ) { cout << "Connection made "; } else if ( msg & MNodeMessage::kConnectionBroken ) { cout << "Connection broken "; } else { return; } cout << plug.info(); if ( msg & MNodeMessage::kOtherPlugSet ) { if ( msg & MNodeMessage::kIncomingDirection ) { cout << " <-- " << otherPlug.info(); } else { cout << " --> " << otherPlug.info(); } } cout << endl; } ////////////////////////////////////////////////////////////////////////// // // Command class declaration // ////////////////////////////////////////////////////////////////////////// class nodeMessageCmd : public MPxCommand { public: nodeMessageCmd() {}; virtual ~nodeMessageCmd(); MStatus doIt( const MArgList& args ); static void* creator(); }; ////////////////////////////////////////////////////////////////////////// // // Command class implementation // ////////////////////////////////////////////////////////////////////////// nodeMessageCmd::~nodeMessageCmd() {} void* nodeMessageCmd::creator() { return new nodeMessageCmd(); } MStatus nodeMessageCmd::doIt( const MArgList& ) // // Takes the nodes that are on the active selection list and adds an // attriubte changed callback to each one. // { MStatus stat; MObject node; MSelectionList list; MCallbackId id; // Register node callbacks for all nodes on the active list. // MGlobal::getActiveSelectionList( list ); for ( unsigned int i=0; i