//- // ========================================================================== // 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. // ========================================================================== //+ // // polyMessageCmd.cpp // // Description: // Sample plug-in that demonstrates how to register/de-register // a callback with the MPolyMessage class. // // This plug-in will register a new command in maya called // "polyMessage" which adds a callback for the all nodes on // the active selection list. A message is printed to stdout // whenever a component id of one of the poly nodes is modified. // #include #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( MUintArray componentIds[], unsigned int count, void *clientData ) { cout << "poly component id modified"; cout << endl; if ( count != MPolyMessage::kLastErrorIndex ) return; unsigned int i, id; unsigned int kDeletedId = MPolyMessage::deletedId(); MUintArray vertexIds = componentIds[MPolyMessage::kVertexIndex]; for ( i = 0; i < vertexIds.length(); i++ ) { id = vertexIds[i]; if ( id == kDeletedId ) cout << "vertex " << i << " deleted" << endl; else if ( i != id ) cout << "vertex " << i << " " << id << endl; } MUintArray edgeIds = componentIds[MPolyMessage::kEdgeIndex]; for ( i = 0; i < edgeIds.length(); i++ ) { id = edgeIds[i]; if ( id == kDeletedId ) cout << "edge " << i << " deleted" << endl; else if ( i != id ) cout << "edge " << i << " " << id << endl; } MUintArray faceIds = componentIds[MPolyMessage::kFaceIndex]; for ( i = 0; i < faceIds.length(); i++ ) { id = faceIds[i]; if ( id == kDeletedId ) cout << "face " << i << " deleted" << endl; else if ( i != id ) cout << "face " << i << " " << id << endl; } } ////////////////////////////////////////////////////////////////////////// // // Command class declaration // ////////////////////////////////////////////////////////////////////////// class polyMessageCmd : public MPxCommand { public: polyMessageCmd() {}; virtual ~polyMessageCmd(); MStatus doIt( const MArgList& args ); static void* creator(); }; ////////////////////////////////////////////////////////////////////////// // // Command class implementation // ////////////////////////////////////////////////////////////////////////// polyMessageCmd::~polyMessageCmd() {} void* polyMessageCmd::creator() { return new polyMessageCmd(); } MStatus polyMessageCmd::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