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; }
//--------------------------------------------------- void DagHelper::setArrayPlugSize ( MPlug& plug, uint size ) { if ( plug.node().isNull() ) return; #if MAYA_API_VERSION >= 800 MStatus status = plug.setNumElements ( size ); CHECK_STAT ( status ); #else MObject node = plug.node(); MString plugPath = plug.info(); if ( node.hasFn ( MFn::kDagNode ) ) { MFnDagNode dagFn ( node ); int dot = plugPath.index ( '.' ); plugPath = dagFn.fullPathName() + plugPath.substring ( dot, plugPath.length() ); } MString command = MString ( "setAttr -s " ) + size + " \"" + plugPath + "\";"; MGlobal::executeCommand ( command ); #endif // MAYA 8.00+ }
MStatus nodeInfo::doIt( const MArgList& args ) // // Description // This method performs the action of the command. // // This method iterates over all selected items and // prints out connected plug and dependency node type // information. // { MStatus stat; // Status code MObject dependNode; // Selected dependency node stat = parseArgs ( args ); if ( !stat ) return stat; // 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 // stat = iter.getDependNode( dependNode ); if ( !stat ) { stat.perror("getDependNode"); continue; } // Create a function set for the dependency node // MFnDependencyNode fnDependNode( dependNode ); // Check the type of the dependency node // MString nodeName = fnDependNode.name(); nodeName += ": "; printType( dependNode, nodeName ); // Get all connected plugs to this node // MPlugArray connectedPlugs; stat = fnDependNode.getConnections( connectedPlugs ); int numberOfPlugs = connectedPlugs.length(); if ( !quiet ) cerr << " Found: " << numberOfPlugs << " connections" << endl; // Print out the dependency node name and attributes // for each plug // for ( int i=0; i<numberOfPlugs; i++ ) { MPlug plug = connectedPlugs[i]; MString pinfo = plug.info(); if ( !quiet ) cerr << " Plug info: " << pinfo << endl; // Now get the plugs that this plug is the // destination of and print the node type. // MPlugArray array; plug.connectedTo( array, true, false ); for ( unsigned int j=0; j<array.length(); j++ ) { MObject mnode = array[j].node(); MString msg( " This plug is a dest of a " ); printType( mnode, msg ); } } } return MS::kSuccess; }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- MStatus CVstWeldNode::compute( const MPlug &mPlug, MDataBlock &mDataBlock ) { if ( mPlug == m_oaWeldOutput || mPlug == m_oaTranslate || mPlug == m_oaRotate || mPlug == m_oaTranslateX || mPlug == m_oaTranslateY || mPlug == m_oaTranslateZ || mPlug == m_oaRotateX || mPlug == m_oaRotateY || mPlug == m_oaRotateZ ) { const MObject geoObj = mDataBlock.inputValue( m_iaWorldGeometry ).data(); if ( geoObj.apiType() == MFn::kMeshData ) { MStatus mStatus; MObject meshObj = mDataBlock.inputValue( m_iaWorldGeometry ).asMeshTransformed(); MFnMesh meshFn( meshObj ); MItMeshPolygon pIt( meshObj ); MPointArray facePoints; MArrayDataHandle wiAH = mDataBlock.inputArrayValue( m_iaWeldInput ); MArrayDataHandle woAH = mDataBlock.outputArrayValue( m_oaWeldOutput, &mStatus ); MArrayDataBuilder woADB = woAH.builder( &mStatus ); const int nWeldCount = wiAH.elementCount(); for ( int i = 0; i < nWeldCount; ++i, wiAH.next() ) { MDataHandle wiDH = wiAH.inputValue(); const MMatrix &offsetMatrix = wiDH.child( m_iaOffsetMatrix ).asMatrix(); const MMatrix &inverseParentSpace = wiDH.child( m_iaInverseParentSpace ).asMatrix(); const MEulerRotation::RotationOrder rotationOrder = static_cast< MEulerRotation::RotationOrder >( wiDH.child( m_iaRotateOrder ).asShort() ); MMatrix geoMatrix; switch ( wiDH.child( m_iaType ).asShort() ) { case kMeshFace: { const int nMeshFaceIndex = wiDH.child( m_iaInt ).asInt(); GetMeshMatrix( pIt, nMeshFaceIndex, geoMatrix ); } break; default: merr << "Unknown Weld Type " << wiDH.child( m_iaType ).asShort() << std::endl; break; } const int nWeldIndex = wiAH.elementIndex(); MDataHandle woDH = woADB.addElement( nWeldIndex ); MTransformationMatrix L( inverseParentSpace * offsetMatrix * geoMatrix ); woDH.child( m_oaTranslate ).set( L.getTranslation( MSpace::kWorld ) ); MEulerRotation e = L.rotation().asEulerRotation(); e.reorder( rotationOrder ); woDH.child( m_oaRotate ).set( e.asVector() ); } } else { merr << "Invalid .inputGeometry data of type: " << geoObj.apiTypeStr() << " found while computing " << mPlug.info() << std::endl; return MS::kFailure; } return MS::kSuccess; } return MS::kUnknownParameter; }