// convert input MSelectionList to the MSelectionlist w/ specified component // e.g from vtx MSelectionList to edge MSelectionList MSelectionList convertVtxSListToCompSList( MSelectionList& selList, int compType ) { // Two step for conversion // 01. convert MSelecitionList to MItSelecitionList // 02. run MItMeshVertex // if switch to vertex, do nothing if (compType == 0) return selList; MObject vtxComp; MDagPath dPathMesh; MItSelectionList vertexCompIt( selList, MFn::kMeshVertComponent ); // one-time for loop for ( ; !vertexCompIt.isDone(); vertexCompIt.next() ) { vertexCompIt.getDagPath( dPathMesh ,vtxComp ); } MItMeshVertex vertexIt( dPathMesh, vtxComp ); MSelectionList resultSelList; // iterate mesh vertec to get tje connected component for( ; !vertexIt.isDone(); vertexIt.next() ) { MSelectionList tmpSelList; MIntArray compIdArray; // if switch to edge, conver vertex to edge if( compType == 1 ) { vertexIt.getConnectedEdges(compIdArray); tmpSelList = convertMIntArrToMselList( compIdArray, dPathMesh, MFn::kMeshEdgeComponent ); } // if switch to face, conver vertex to face if( compType == 2 ) { vertexIt.getConnectedFaces(compIdArray); tmpSelList = convertMIntArrToMselList( compIdArray, dPathMesh, MFn::kMeshPolygonComponent ); } // merge new edge indice into current selection list // if new item has exist, not merge it. resultSelList.merge(tmpSelList, MSelectionList::kMergeNormal); } return resultSelList; }
MStatus lrutils::getObjFromName(MString name, MObject & obj) { MStatus status; MSelectionList selection; status = selection.add( name, true ); MyCheckStatusReturn(status, "add node \""+name+"\" to selection failed."); if(selection.length() ) { selection.getDependNode(0, obj); status = MS::kSuccess; } return status; }
void createIK2BsolverAfterOpen(void *clientData) // // This method creates the ik2Bsolver after a File->Open // if the ik2Bsolver does not exist in the loaded file. // { MSelectionList selList; MGlobal::getSelectionListByName("ik2Bsolver", selList); if (selList.length() == 0) { MGlobal::getActiveSelectionList( selList ); MGlobal::executeCommand("createNode -n ik2Bsolver ik2Bsolver"); MGlobal::setActiveSelectionList( selList ); } }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- MDagPath CVsSkinnerCmd::GetSpecifiedSkinnerNode() { MSelectionList skinnerNodes; MSelectionList optSelectionList; m_undo.ArgDatabase().getObjects( optSelectionList ); GetSpecifiedSkinnerNodes( optSelectionList, skinnerNodes ); MDagPath mDagPath; if ( skinnerNodes.length() == 0U ) return mDagPath; if ( skinnerNodes.length() > 1U ) { skinnerNodes.getDagPath( 0U, mDagPath ); mwarn << "Using vsSkinnerNode " << mDagPath.partialPathName() << ", ignoring extra vsSkinnerNode"; if ( skinnerNodes.length() > 2U ) mwarn << "s"; mwarn << ":"; for ( uint i( 1U ); i != skinnerNodes.length(); ++i ) { skinnerNodes.getDagPath( i, mDagPath ); mwarn << " " << mDagPath.partialPathName(); } mwarn << std::endl; } skinnerNodes.getDagPath( 0U, mDagPath ); return mDagPath; }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- MStatus CVsSkinnerCmd::FindSkinnerNodesInHierarchy( const MDagPath &iDagPath, MSelectionList &oList ) { MStatus retVal( MS::kFailure ); MDagPath rDagPath( iDagPath ); // Root dag path while ( rDagPath.length() > 1U ) { rDagPath.pop(); } MDagPath mDagPath; MDagPath sDagPath; uint nShapes; MItDag dIt; if ( rDagPath.length() ) { dIt.reset( rDagPath ); } for ( ; !dIt.isDone(); dIt.next() ) { if ( !dIt.getPath( mDagPath ) ) continue; mDagPath.numberOfShapesDirectlyBelow( nShapes ); for ( uint i( 0U ); i != nShapes; ++i ) { sDagPath = mDagPath; sDagPath.extendToShapeDirectlyBelow( i ); if ( !IsSkinnerNode( sDagPath ) ) continue; oList.add( sDagPath, MObject::kNullObj, true ); retVal = MS::kSuccess; } if ( !ConnectedToSkinnerNode( mDagPath, sDagPath ) ) continue; oList.add( sDagPath, MObject::kNullObj, true ); retVal = MS::kSuccess; } return retVal; }
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<list.length(); i++ ) { list.getDependNode( i, node ); MDagPath dp; MObject shapeNode = node; if ( MS::kSuccess == MDagPath::getAPathTo( node, dp ) ) if ( MS::kSuccess == dp.extendToShape() ) shapeNode = dp.node(); bool wantIdChanges[3]; wantIdChanges[MPolyMessage::kVertexIndex] = true; wantIdChanges[MPolyMessage::kEdgeIndex] = true; wantIdChanges[MPolyMessage::kFaceIndex] = true; id = MPolyMessage::addPolyComponentIdChangedCallback( shapeNode, wantIdChanges, 3, userCB, NULL, &stat); // If the callback was successfully added then add the // callback id to our callback table so it can be removed // when the plugin is unloaded. // if ( stat ) { callbackIds.append( id ); } else { cout << "MPolyMessage.addCallback failed\n"; } } return stat; }
MStatus FillStrandGaps::doIt(const MArgList & args) { std::list<MObject> targets; MStatus status = ArgList_GetModelObjects(args, syntax(), "-t", targets); if (status != MStatus::kNotFound && status != MStatus::kSuccess) { HMEVALUATE_RETURN_DESCRIPTION("ArgList_GetModelObjects", status); } if (targets.empty()) { MSelectionList activeSelectionList; HMEVALUATE_RETURN(status = MGlobal::getActiveSelectionList(activeSelectionList), status); if (activeSelectionList.length() > 0) { for (unsigned int i = 0; i < activeSelectionList.length(); ++i) { MObject object; HMEVALUATE_RETURN(status = activeSelectionList.getDependNode(i, object), status); MFnDagNode dagNode(object); MTypeId typeId; HMEVALUATE_RETURN(typeId = dagNode.typeId(&status), status); if (typeId == HelixBase::id || typeId == Helix::id) targets.push_back(object); else MGlobal::displayWarning(MString("Ignoring unknown object \"") + dagNode.fullPathName() + "\""); } } else { /* * Extract all helices */ MItDag itDag(MItDag::kDepthFirst, MFn::kPluginTransformNode, &status); HMEVALUATE_RETURN_DESCRIPTION("MItDag::#ctor", status); for (; !itDag.isDone(); itDag.next()) { MObject object; HMEVALUATE_RETURN(object = itDag.currentItem(&status), status); bool is_helix; HMEVALUATE_RETURN(is_helix = MFnDagNode(object).typeId(&status) == Helix::id, status); if (is_helix) targets.push_back(object); } } } return m_operation.fill(targets); }
//this function adds the layer objects in mAnimLayers to the start of the selection list. //this is used when exporting to make sure the animationlayers come first void atomAnimLayers::addLayersToStartOfSelectionList(MSelectionList &list) { if(mAnimLayers.length() > 0 ) { MSelectionList layers; for(unsigned int i =0; i<mAnimLayers.length();++i) { layers.add(mAnimLayers[i], true); } layers.merge(list); list = layers; } }
MStatus testSelectAddAttribute::doIt( const MArgList& args ) { MDagPath node; MObject component; MSelectionList list; MFnDagNode nodeFn; MGlobal::getActiveSelectionList( list ); for ( unsigned int index = 0; index < list.length(); index++ ) { list.getDagPath( index, node, component ); nodeFn.setObject( node ); cout<<nodeFn.name().asChar( ) << "is selected" << endl; } return MS::kSuccess; }
/* override */ bool apiSimpleShapeUI::select( MSelectInfo &selectInfo, MSelectionList &selectionList, MPointArray &worldSpaceSelectPts ) const // // Description: // // Main selection routine // // Arguments: // // selectInfo - the selection state information // selectionList - the list of selected items to add to // worldSpaceSelectPts - // { bool selected = false; bool componentSelected = false; bool hilited = false; hilited = (selectInfo.displayStatus() == M3dView::kHilite); if ( hilited ) { componentSelected = selectVertices( selectInfo, selectionList, worldSpaceSelectPts ); selected = selected || componentSelected; } if ( !selected ) { // NOTE: If the geometry has an intersect routine it should // be called here with the selection ray to determine if the // the object was selected. selected = true; MSelectionMask priorityMask( MSelectionMask::kSelectNurbsSurfaces ); MSelectionList item; item.add( selectInfo.selectPath() ); MPoint xformedPt; if ( selectInfo.singleSelection() ) { MPoint center = surfaceShape()->boundingBox().center(); xformedPt = center; xformedPt *= selectInfo.selectPath().inclusiveMatrix(); } selectInfo.addSelection( item, xformedPt, selectionList, worldSpaceSelectPts, priorityMask, false ); } return selected; }
MStatus animExport::exportSelected( ofstream &animFile, MString ©Flags, bool nodeNames /* false */, bool verboseUnits /* false */) { MStatus status = MS::kFailure; // If the selection list is empty, then there are no anim curves // to export. // MSelectionList sList; MGlobal::getActiveSelectionList(sList); if (sList.isEmpty()) { MString msg = MStringResource::getString(kNothingSelected, status); MGlobal::displayError(msg); return (MS::kFailure); } // Copy any anim curves to the API clipboard. // int result = 0; MString command(copyFlags); if (MS::kSuccess != (status = MGlobal::executeCommand(command, result, false, true))) { MStatus stringStat; MString msg = MStringResource::getString(kAnimCurveNotFound, stringStat); MGlobal::displayError(msg); return status; } if (result == 0 || MAnimCurveClipboard::theAPIClipboard().isEmpty()) { MString msg = MStringResource::getString(kAnimCurveNotFound, status); MGlobal::displayError(msg); return (MS::kFailure); } if (MS::kSuccess != ( status = fWriter.writeClipboard(animFile, MAnimCurveClipboard::theAPIClipboard(), nodeNames, verboseUnits))) { return (MS::kFailure); } return status; }
//----------------------------------------------------------------------------- // Get the starting list of objects to export //----------------------------------------------------------------------------- MStatus CVstSmdIOCmd::GetOptSelection( const MArgDatabase &mArgDatabase, MSelectionList &mSelectionList ) { if ( mArgDatabase.isFlagSet( kOptSelection ) ) { // Get the user's specified selection of stuff to export if ( !mArgDatabase.getObjects( mSelectionList ) ) { MGlobal::displayError( "Cannot get list of specified objects to export" ); return MS::kFailure; } else if ( mSelectionList.isEmpty() ) { MGlobal::displayError( "-export -selection specified but nothing is selected" ); return MS::kFailure; } } else { MDagPath mDagPath; const bool exportInvisible( mArgDatabase.isFlagSet( kOptExportInvisible ) ); for ( MItDag dagIt( MItDag::kBreadthFirst, MFn::kDagNode ); !dagIt.isDone() && dagIt.depth() <= 1; dagIt.next() ) { if ( dagIt.depth() == 1) { if ( dagIt.getPath( mDagPath ) ) { if ( exportInvisible || ValveMaya::IsPathVisible( mDagPath ) ) { mSelectionList.add( mDagPath, MObject::kNullObj, true ); } } } } } if ( mSelectionList.isEmpty() ) { MGlobal::displayError( "Cannot find anything to export" ); return MS::kFailure; } return MS::kSuccess; }
// Remove any DAG object not in the selectedObjects list. void ShapeMonitor::stopWatchingUnselectedDagObjects(MSelectionList& selectedObjects) { // For each monitored object... for (int i = monitoredObjectsPtrArray.length()-1; i >= 0; i--) { MonitoredObject *pMonObject = monitoredObjectsPtrArray[i]; MStatus stat; // Get an MObject for the MonitoredObject->mayaNodeName. MDagPath dagpath; MSelectionList selList; selList.add(pMonObject->mayaNodeName); stat = selList.getDagPath(0, dagpath); // If the MObject is a DAG node... if (stat) { bool found = false; // Check if the dag path is included in the selectedObjects list. // For example, say that dagpath = "|group1|group2|pSphere|pSphereShape", // selectedObjects contains "|group1|group2". // We first check if dagpath is included in selectedObjects. If that's not the // case, we pop() one component, so that dagpath = "|group1|group2|pSphere", then // check again. We do that until either the dagpath is found to be included in // the selectedObjects list, or until there's no component left in dagpath. while (!found && dagpath.length() > 0) { // Since we store the shape name (as opposed to the parent transform dagpath), // we need to pop() to get the parent transform dagpath. dagpath.pop(); MObject component; // Check if the dag path is included in the objects list. if (selectedObjects.hasItemPartly(dagpath, component)) found = true; } // If the object was not in the selectedObjects list, stop watching it. if (!found) stopWatching(pMonObject->mayaNodeName); } } }
bool OpenSubdivDrawOverride::getSelectionStatus(const MDagPath& objPath) const { // retrieve the selection status of the node MStatus status; MSelectionList selectedList; status = MGlobal::getActiveSelectionList(selectedList); if(!status) return false; MDagPath pathCopy = objPath; do { if(selectedList.hasItem(pathCopy)) return true; status = pathCopy.pop(); } while(status); return false; }
// ouput the MselectList of VERTEX Component MSelectionList getVtxSelList( MDagPath& inDagPath, const int inCompArray[], int inCountArray ) { // vtx process // MSelectionList vtxSelList; // Create a MFnSingleIndexedComponent object of type kMeshVertComponent. MFnSingleIndexedComponent singleIndexCompFn; MObject components = singleIndexCompFn.create(MFn::kMeshVertComponent); MIntArray elementArray( inCompArray, inCountArray); // Add the element indices singleIndexCompFn.addElements(elementArray); // Add the element to the selection list. vtxSelList.add( inDagPath, components ); return vtxSelList; }
MStatus lockEvent::parseArgs( const MArgList &args ) { MStatus status; MArgDatabase argData( syntax(), args ); fAttach = kAttachDV; fOverrideFlag = kOverrideDV; fClearCB = kClearCBDV; // begin-parse-args if ( argData.isFlagSet( kClearCB ) ) { fClearCB = !kClearCBDV; } if ( argData.isFlagSet( kOverride ) ) { bool tmp; status = argData.getFlagArgument( kOverride, 0, tmp ); if ( !status ) { MGlobal::displayError( "override flag parsing failed" ); return status; } fOverrideFlag = !kOverrideDV; fOverrideVal = tmp; } if ( argData.isFlagSet( kAttach ) ) { unsigned int tmp; status = argData.getFlagArgument( kAttach, 0, tmp ); if ( !status ) { MGlobal::displayError( "attach flag parsing failed" ); return status; } fAttach = tmp; } if ( fAttach ) { status = argData.getObjects( theList ); if ( theList.length() == 0 ) { MString msg = "You must specify a node/plug to attach to!"; MGlobal::displayError(msg); status = MS::kFailure; } } // Ensure that the caller did not specify too many arguments! // if ( status && fAttach && fOverrideFlag ) { MString msg = "You specified too many flags!" ; MGlobal::displayError(msg); status = MS::kFailure; } // end-parse-args return status; }
MStatus liqWriteArchive::redoIt() { try { MString objName = objectNames[0]; // TEMP - just handling one object at the moment // get a handle on the named object MSelectionList selList; selList.add(objName); MDagPath objDagPath; MStatus status = selList.getDagPath(0, objDagPath); if (!status) { MGlobal::displayError("Error retrieving object " + objName); return MS::kFailure; } // test that the output file is writable FILE *f = fopen(outputFilename.asChar(), "w"); if (!f) { MGlobal::displayError("Error writing to output file " + outputFilename + ". Check file permissions there"); return MS::kFailure; } fclose(f); #if defined( PRMAN ) || defined( DELIGHT ) // binary or ascii RtString format[1] = {"ascii"}; if ( binaryRib ) format[0] = "binary"; RiOption( "rib", "format", ( RtPointer )&format, RI_NULL); #endif // write the RIB file RiBegin(const_cast<char*>(outputFilename.asChar())); writeObjectToRib(objDagPath, outputRootTransform); RiEnd(); } catch (...) { MGlobal::displayError("Caught exception in liqWriteArchive::redoIt()"); return MS::kFailure; } return MS::kSuccess; }
void skinClusterWeights::doItQuery() { MStatus status; unsigned int i, j; MDoubleArray weights; // To allow "skinClusterWeights -q" to return empty double array setResult(weights); MSelectionList selList; for (i = 0; i < geometryArray.length(); i++) { MDagPath dagPath; MObject component; selList.clear(); selList.add(geometryArray[i]); MStatus status = selList.getDagPath(0, dagPath, component); if (status != MS::kSuccess) { continue; } if (component.isNull()) dagPath.extendToShape(); MObject skinCluster = findSkinCluster(dagPath); if (!isSkinClusterIncluded(skinCluster)) { continue; } MFnSkinCluster skinClusterFn(skinCluster, &status); if (status != MS::kSuccess) { continue; } MIntArray influenceIndexArray; populateInfluenceIndexArray(skinClusterFn, influenceIndexArray); weights.clear(); skinClusterFn.getWeights(dagPath, component, influenceIndexArray, weights); if (weights.length() > 0) { for (j = 0; j < weights.length(); j++) { appendToResult(weights[j]); } } } }
MStatus NeuronForMayaCmd::doIt( const MArgList& args ) { MStatus status; status = parseArgs( args ); if( status != MStatus::kSuccess) { MGlobal::displayError( "parameters are not correct." ); return status; } MSelectionList sl; sl.add( mDeviceName ); MObject deviceObj; status = sl.getDependNode(0, deviceObj ); if(status != MStatus::kSuccess ) { MGlobal::displayError("Please create your device first."); return status; } MFnDependencyNode fnDevice(deviceObj); MString ip = fnDevice.findPlug( "inputIp", &status ).asString(); int port = fnDevice.findPlug("inputPort", &status).asInt(); if( mStart ){ // to register the 3 callback to fetch data from Neuron BRRegisterFrameDataCallback(NULL, NeuronForMayaDevice::myFrameDataReceived ); //BRRegisterCommandDataCallback(NULL, NeuronForMayaDevice::myCommandDataReceived ); BRRegisterSocketStatusCallback (NULL, NeuronForMayaDevice::mySocketStatusChanged ); socketInfo = BRConnectTo(const_cast<char*> (ip.asChar()), port); if(socketInfo == NULL ) MGlobal::displayError("Failed to connect to device."); } else { // stop socket BRCloseSocket( socketInfo); } return MStatus::kSuccess; }
void btSPHCmd::getAABB(const MString &name, MPoint& min, MPoint &max) { _LogFunctionCall("btSPHCmd::getAABB("<< name<<")"); MStatus status = MS::kSuccess; MSelectionList sList; IfMErrorWarn(MGlobal::getSelectionListByName(name, sList)); assert(sList.length()==1); MDagPath dp; IfMErrorWarn(sList.getDagPath(0, dp)); IfMErrorWarn(dp.extendToShape());//particle shape MFnMesh meshFn( dp, &status ); IfMErrorWarn(status); MPointArray positions; IfMErrorWarn(meshFn.getPoints(positions, MSpace::kWorld)); const size_t LEN = positions.length(); for(size_t i=0; i<LEN; ++i) { const MPoint &p = positions[i]; if(p.x<min.x) min.x = p.x; if(p.y<min.y) min.y = p.y; if(p.z<min.z) min.z = p.z; if(p.x>max.x) max.x = p.x; if(p.y>max.y) max.y = p.y; if(p.z>max.z) max.z = p.z; } // MPlug plug; // getPlugValue_asDistance(min.x, meshFn, "boundingBoxMinX"); // getPlugValue_asDistance(min.y, meshFn, "boundingBoxMinY"); // getPlugValue_asDistance(min.z, meshFn, "boundingBoxMinZ"); // getPlugValue_asDistance(max.x, meshFn, "boundingBoxMaxX"); // getPlugValue_asDistance(max.y, meshFn, "boundingBoxMaxY"); // getPlugValue_asDistance(max.z, meshFn, "boundingBoxMaxZ"); }
void peltOverlap::createBoundingCircle(const MStringArray &flattenFaces, MFloatArray ¢er, MFloatArray &radius) // // Description // Represent a face by a center and radius, i.e. // center = {center1u, center1v, center2u, center2v, ... } // radius = {radius1, radius2, ... } // { center.setLength(2 * flattenFaces.length()); radius.setLength(flattenFaces.length()); for(unsigned int i = 0; i < flattenFaces.length(); i++) { MSelectionList selList; selList.add(flattenFaces[i]); MDagPath dagPath; MObject comp; selList.getDagPath(0, dagPath, comp); MItMeshPolygon iter(dagPath, comp); MFloatArray uArray, vArray; iter.getUVs(uArray, vArray); // Loop through all vertices to construct edges/rays float cu = 0.f; float cv = 0.f; unsigned int j; for(j = 0; j < uArray.length(); j++) { cu += uArray[j]; cv += vArray[j]; } cu = cu / uArray.length(); cv = cv / vArray.length(); float rsqr = 0.f; for(j = 0; j < uArray.length(); j++) { float du = uArray[j] - cu; float dv = vArray[j] - cv; float dsqr = du*du + dv*dv; rsqr = dsqr > rsqr ? dsqr : rsqr; } center[2*i] = cu; center[2*i+1] = cv; radius[i] = sqrt(rsqr); } }
void ShapeMonitor::watch(MString mayaNodeName, MonitoredObject* pMon) // // Description: // // Start watching the specified mayaNodeName for changes. (If the node is part of the DAG, that // should be a fully-specified DAG name). This function will store all available information // inside a MonitorObject for future reference. // // Arguments: // mayaNodeName: DG (or fully-qualified DAG) name. // uniqueTextureName: The corresponding texture name. This texture should correspond // directly to an IFX texture resource. { // Check if, per chance, this monitored object already exists. // If it does, no need to create a new one. if (retrieveMonitorObject(mayaNodeName)) return; MStatus stat; // // Get the node. // MObject node; MSelectionList selList; selList.add(mayaNodeName); selList.getDependNode(0, node); // // Attach the callbacks (dirty or renamed node) // pMon->mayaNodeName = mayaNodeName; pMon->dirtyCallbackId = MNodeMessage::addNodeDirtyCallback(node, watchedObjectDirtyCallback, pMon, &stat ); assert(stat); pMon->renamedCallbackId = MNodeMessage::addNameChangedCallback ( node, watchedObjectRenamedCallback, pMon, &stat); assert(stat); // Store the pertinent information in the Monitored Objects Array. monitoredObjectsPtrArray.append(pMon); }
inline static MObject getNode(MString name,MStatus *returnStatus) { MObject node; MSelectionList list; *returnStatus=MGlobal::getSelectionListByName(name,list); if(MS::kSuccess!=*returnStatus){ ERROR("[raytraceMayaRenderView] Cound't get node :"+ name +". There might be multiple nodes called "+name); return node; } *returnStatus=list.getDependNode(0,node); if(MS::kSuccess!=*returnStatus){ ERROR("[raytraceMayaRenderView] Cound't get node :"+ name +". There might be multiple nodes called "+name); return MObject::kNullObj; } return node; }
MObject getObjFromName(MString name, MStatus& stat) { MObject obj; MSelectionList list; // Attempt to add the given name to the selection list, // then get the corresponding dependency node handle. if (!list.add(name) || !list.getDependNode(0, obj)) { // Failed. stat = MStatus::kInvalidParameter; return obj; } // Successful. stat = MStatus::kSuccess; return obj; }
MStatus deletedMessage::doIt( const MArgList& args ) { MStatus status = MS::kSuccess; MArgDatabase argData(syntax(), args); MSelectionList objects; argData.getObjects(objects); for (unsigned int i = 0; i < objects.length(); i++) { MObject node; objects.getDependNode(i, node); callbackIds.append( MNodeMessage::addNodeAboutToDeleteCallback (node, aboutToDeleteCB, NULL, &status) ); if (!status) { MGlobal::displayWarning("Could not attach about to delete callback for node."); continue; } callbackIds.append( MNodeMessage::addNodePreRemovalCallback (node, preRemovalCB, NULL, &status) ); if (!status) { MGlobal::displayWarning("Could not attach pre-removal callback for node."); continue; } if (!nodeRemovedCBRegistered) { callbackIds.append( MDGMessage::addNodeRemovedCallback(removeCB, "dependNode", NULL, &status) ); if (!status) { MGlobal::displayWarning("Could not attach node removal callback."); continue; } nodeRemovedCBRegistered = true; } } return status; }
MStatus liqGetAttr::doIt( const MArgList& args ) { CM_TRACE_FUNC("liqGetAttr::doIt(args)"); MStatus status; unsigned i; MString nodeName, attrName; MSelectionList nodeList; for ( i = 0; i < args.length(); i++ ) { if ( MString( "-debug" ) == args.asString( i, &status) ) { } else if ( MString( "-node" ) == args.asString( i, &status) ) { i++; nodeName = args.asString( i, &status ) ; } else if ( MString( "-attr" ) == args.asString( i, &status) ) { i++; attrName = args.asString( i, &status ); } } nodeList.add( nodeName ); MObject depNodeObj; nodeList.getDependNode(0, depNodeObj); MFnDependencyNode depNode( depNodeObj ); MPlug attrPlug = depNode.findPlug( attrName ); MObject plugObj; attrPlug.getValue( plugObj ); if( plugObj.apiType() == MFn::kDoubleArrayData ) { MFnDoubleArrayData fnDoubleArrayData( plugObj ); const MDoubleArray& doubleArrayData( fnDoubleArrayData.array( &status ) ); for ( i = 0; i < doubleArrayData.length(); i++ ) appendToResult( doubleArrayData[i] ); } return MS::kSuccess; };
// // Method to add in a light "prune" list. Only selected // lights will be have their shadows requested, and // be used for the scene render shader override. // MStatus viewRenderOverrideShadows::updateLightList() { mLightList.clear(); shadowPrepass* shadowOp = (shadowPrepass*)mRenderOperations[kShadowPrePass]; sceneRender* sceneOp = (sceneRender*)mRenderOperations[kMaya3dSceneRender]; if (!shadowOp || !sceneOp) return MStatus::kFailure; // Scan selection list for active lights // MSelectionList selectList; MDagPath dagPath; MObject component; MGlobal::getActiveSelectionList( selectList ); for (unsigned int i=0; i<selectList.length(); i++) { selectList.getDagPath( i, dagPath, component ); dagPath.extendToShape(); if ( dagPath.hasFn( MFn::kLight ) ) { mLightList.add( dagPath ); } } // Set light list to prune which lights to request shadows for // if (mLightList.length()) shadowOp->setLightList( &mLightList ); else shadowOp->setLightList( NULL ); // Set light list to prune which lights to bind for scene shader // if (mLightList.length()) sceneOp->setLightList( &mLightList ); else sceneOp->setLightList( NULL ); return MStatus::kSuccess; }
// extract the component from a MSelectionList MObject getCompListFromSList( MSelectionList& sList ) { MDagPath dPath; MObject compList; sList.getDagPath( 0, dPath, compList ); MStringArray strArr; MGlobal::getFunctionSetList( compList, strArr ); MGlobal::displayInfo( MString("Array: ") + strArr[0] + strArr[1] ); return compList; }
MStatus HesperisCmd::doIt(const MArgList &args) { MStatus status = parseArgs( args ); if( status != MS::kSuccess ) return status; if(m_ioMode == IOHelp) return printHelp(); MSelectionList selList; MGlobal::getActiveSelectionList(selList); if(selList.length() < 1) { MGlobal::displayInfo(" empty selction"); return MS::kSuccess; } if(m_ioMode == IOWrite) return writeSelected(selList); if(m_ioMode == IOFieldDeform) return deformSelected(); return MS::kSuccess; }
MStatus animImport::importAnim(ifstream &animFile, const MString &pasteFlags) { MStatus status = MS::kFailure; MAnimCurveClipboard::theAPIClipboard().clear(); // If the selection list is empty, there is nothing to import. // MSelectionList sList; MGlobal::getActiveSelectionList(sList); if (sList.isEmpty()) { MString msg = MStringResource::getString(kNothingSelected, status); MGlobal::displayError(msg); return (MS::kFailure); } if (MS::kSuccess != (status = fReader.readClipboard(animFile, MAnimCurveClipboard::theAPIClipboard()))) { return status; } if (MAnimCurveClipboard::theAPIClipboard().isEmpty()) { return (MS::kFailure); } MString command("pasteKey -cb api "); command += pasteFlags; int result; if (MS::kSuccess != (status = MGlobal::executeCommand(command, result, false, true))) { MString msg = MStringResource::getString(kPasteFailed, status); MGlobal::displayError(msg); return status; } return status; }