//- // ========================================================================== // 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. // ========================================================================== //+ //////////////////////////////////////////////////////////////////////// // // Adds a dynamic attribute to selected dependency nodes. // Dynamic attributes can be used as blind data. // // Usage: Load this plugin. // Select an object in Maya, and execute the MEL command // blindShortData. To see the new attribute, bring up the // Attribute Editor window and look under "Extras" tab. // //////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include class blindShortData : public MPxCommand { public: blindShortData() {}; virtual ~blindShortData(); MStatus doIt( const MArgList& args ); virtual MStatus redoIt(); static void* creator(); }; blindShortData::~blindShortData() {} void* blindShortData::creator() { return new blindShortData(); } MStatus blindShortData::doIt( const MArgList& ) { MStatus stat = redoIt(); return stat; } MStatus blindShortData::redoIt() // This method performs the action of the command. // // Iterate over all selected items and for each attach a new // dynamic attribute. { MStatus stat; // Status code MObject dependNode; // Selected dependency node // Create a selection list iterator // MSelectionList slist; MGlobal::getActiveSelectionList( slist ); MItSelectionList iter( slist, MFn::kInvalid, &stat ); // Iterate over all selected dependency nodes // for ( ; !iter.isDone(); iter.next() ) { // Get the selected dependency node and create // a function set for it // if ( MS::kSuccess != iter.getDependNode( dependNode ) ) { cerr << "Error getting the dependency node" << endl; continue; } MFnDependencyNode fnDN( dependNode, &stat ); if ( MS::kSuccess != stat ) { cerr << "Error creating MFnDependencyNode" << endl; continue; } // Create a new attribute to use as out blind data // MFnNumericAttribute fnAttr; const MString fullName( "blindData" ); const MString briefName( "bd" ); double attrDefault = 99; MObject newAttr = fnAttr.create( fullName, briefName, MFnNumericData::kShort, attrDefault, &stat ); if ( MS::kSuccess != stat ) { cerr << "Error creating new attribute" << endl; continue; } // Now add the new attribute to this dependency node // stat = fnDN.addAttribute(newAttr,MFnDependencyNode::kLocalDynamicAttr); if ( MS::kSuccess != stat ) { cerr << "Error adding dynamic attribute" << endl; } } return MS::kSuccess; } ////////////////////////////////////////////////////////////////////////////// // // The following routines are used to register/unregister // the command we are creating within Maya // ////////////////////////////////////////////////////////////////////////////// MStatus initializePlugin( MObject obj ) { MStatus status; MFnPlugin plugin( obj, "Alias", "3.0", "Any"); status = plugin.registerCommand( "blindShortData", blindShortData::creator ); if (!status) { status.perror("registerCommand"); return status; } return status; } MStatus uninitializePlugin( MObject obj) { MStatus status; MFnPlugin plugin( obj ); status = plugin.deregisterCommand( "blindShortData" ); if (!status) { status.perror("deregisterCommand"); return status; } return status; }