//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- 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 particlePathsCmd::parseArgs( const MArgList& args ) { MArgDatabase argData(syntax(), args); // // Parse the time flags // if (argData.isFlagSet(startFlag)) { argData.getFlagArgument(startFlag, 0, start); } if (argData.isFlagSet(finishFlag)) { argData.getFlagArgument(finishFlag, 0, finish); } if (argData.isFlagSet(incrementFlag)) { argData.getFlagArgument(incrementFlag, 0, increment); } if (finish <= start || increment <= 0.0) { MGlobal::displayError( "Invalid time arguments." ); return MS::kFailure; } // // Get the particle system object // MSelectionList selectList; argData.getObjects(selectList); if( selectList.length() < 1 ) { MGlobal::displayError( "Missing particle node name argument." ); return MS::kFailure; } else if( selectList.length() > 1 ) { MGlobal::displayError( "Too many particle nodes given." ); return MS::kFailure; } selectList.getDependNode(0,particleNode); if (particleNode.isNull() || !particleNode.hasFn(MFn::kParticle)) { MGlobal::displayError( "Invalid node argument." ); return MS::kFailure; } return MS::kSuccess; }
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); }
// ------------------------------------------------------------ void SceneGraph::findForcedNodes() { MStatus status; if ( mExportSelectedOnly ) { MSelectionList selectedItems; MGlobal::getActiveSelectionList ( selectedItems ); uint selectedCount = selectedItems.length(); MDagPathArray queue; for ( uint i = 0; i < selectedCount; ++i ) { MDagPath selectedPath; status = selectedItems.getDagPath ( i, selectedPath ); if ( status == MStatus::kSuccess ) queue.append ( selectedPath ); } while ( queue.length() > 0 ) { MDagPath selectedPath = queue[queue.length() - 1]; queue.remove ( queue.length() - 1 ); // Queue up the children. uint childCount = selectedPath.childCount(); for ( uint i = 0; i < childCount; ++i ) { MObject node = selectedPath.child ( i ); MDagPath childPath = selectedPath; childPath.push ( node ); queue.append ( childPath ); } // Look for a mesh if ( selectedPath.node().hasFn ( MFn::kMesh ) ) { // export forced nodes in path addForcedNodes ( selectedPath ); } } } else { for ( MItDag dagIt ( MItDag::kBreadthFirst ); !dagIt.isDone(); dagIt.next() ) { MDagPath currentPath; status = dagIt.getPath ( currentPath ); if ( status == MStatus::kSuccess ) { MFnDagNode node ( currentPath ); String nodeName = node.name().asChar(); if ( currentPath.node().hasFn ( MFn::kMesh ) ) { // export forced nodes in path addForcedNodes ( currentPath ); } } } } }
//this function creates missing animation layers and places it in the correct order void atomAnimLayers::createMissingAnimLayers(const MStringArray &animLayers) { for(unsigned int k=0; k < animLayers.length(); ++k) { MSelectionList list; list.add(animLayers[k]); if(list.length()!=1) //if not in the list then not in the scene so create it, and the previous one WILL be in the scene so attach to it { MString prevLayerName; if(k>0) prevLayerName = animLayers[k-1]; //todo need a better way to handle the root layer //this fixes an issue where when you create an animation layer for the base it creates 2 layers the BaseAnimation //and a default animLayer1, where if you create the same thing in the UI the second one is named AnimLayer1, with //a cap A. So we are getting an extra animLayer1 created, which is a little messy. This stops that //but we need to revisit. Also seems like you can't rename BaseAnimation, but not sure what it is in different //languages. It's a node so maybe it never changes? if(k > 0 || animLayers[k] != MString("BaseAnimation") || animLayers.length()==0) //we know we are creating more than 1 so the BaseAnimation will { //be created next time so dont create it unless only creating a BaseAnimation createAnimLayer(animLayers[k],prevLayerName); } } } }
// -------------------------------------------------------------------- MStatus SceneGraph::addInstancedDagPaths ( MSelectionList& selectionList ) { MStatus status; int length = selectionList.length ( &status ); if ( status != MStatus::kSuccess ) return MStatus::kFailure; for ( int i=0; i<length; i++ ) { MDagPath dagPath; if ( selectionList.getDagPath ( i, dagPath ) != MStatus::kSuccess ) return MStatus::kFailure; if ( dagPath.isInstanced() ) { int includedInstance=dagPath.instanceNumber ( &status ); if ( status != MStatus::kSuccess ) return MStatus::kFailure; MObject object=dagPath.node ( &status ); if ( status != MStatus::kSuccess ) return MStatus::kFailure; MDagPathArray paths; if ( MDagPath::getAllPathsTo ( object, paths ) != MStatus::kSuccess ) return MStatus::kFailure; int numPaths=paths.length(); for ( int p=0; p<numPaths; p++ ) if ( p!=includedInstance ) selectionList.add ( paths[p] ); } } return MStatus::kSuccess; }
// // This callback gets called for the PostToolChanged and SelectionChanged events. // It checks to see if the current context is the dragAttrContext, which is the context // applied by default when a custom numeric attribute is selected in the channel box. // In this case, the customAttrManip context is set. // static void eventCB(void * data) { // This check prevents recursion from happening when overriding the manip. if (isSetting) return; MSelectionList selList; MGlobal::getActiveSelectionList(selList); MString curCtx = ""; MGlobal::executeCommand("currentCtx", curCtx); MDagPath path; MObject dependNode; for (unsigned int i=0; i<selList.length(); i++) { if ((selList.getDependNode(i, dependNode)) == MStatus::kSuccess) { MFnTransform node; if (node.hasObj(dependNode)) node.setObject(dependNode); else continue; if (node.typeId() == rockingTransformNode::id) { // If the current context is the dragAttrContext, check to see // if the custom channel box attributes are selected. If so, // attach the custom manipulator. if ((curCtx == "dragAttrContext") || (curCtx == "")) { // Make sure that the correct channel box attributes are selected // before setting the tool context. unsigned int c; MStringArray cboxAttrs; MGlobal::executeCommand( "channelBox -q -selectedMainAttributes $gChannelBoxName", cboxAttrs); for (c=0; c<cboxAttrs.length(); c++) { if (cboxAttrs[c] == customAttributeString) { isSetting = true; MGlobal::executeCommand("setToolTo myCustomAttrContext"); isSetting = false; return; } } } if ((curCtx == "moveSuperContext") || (curCtx == "manipMoveContext") || (curCtx == "")) { isSetting = true; MGlobal::executeCommand("setToolTo myCustomTriadContext"); isSetting = false; return; } } } } }
MStatus linearFrictionCmd::doIt(const MArgList& args) { MStatus stat; MArgDatabase argData(syntax(),args,&stat); if(argData.isFlagSet(lfFlag))argData.getFlagArgument(lfFlag,0,linearFriction); MSelectionList activeSelect; MGlobal::getActiveSelectionList(activeSelect); for(int i=0;i<activeSelect.length();i++) { MObject tNode; activeSelect.getDependNode(i,tNode); MFnDagNode fnDagNode(tNode); MObject pNode=fnDagNode.child(0); MFnDependencyNode fnNode(pNode); //MString name=fnNode1.name().asChar(); if(fnNode.typeId() == particleNode::typeId) { //get solver message attribute from particleNode MPlug(pNode, particleNode::linearFriction).setValue(linearFriction); } } return dgMod.doIt(); }
// ------------------------------------------------------ // Unlike Maya's default behavior, we want to consider set membership to be inheritable bool SetHelper::isMemberOfSet ( const MDagPath& dagPath, MFnSet& Set ) { if ( Set.isMember ( dagPath ) ) { return true; } else { MFnDagNode dagNode ( dagPath ); MSelectionList setMembers; Set.getMembers ( setMembers, true ); for ( unsigned int i = 0; i < setMembers.length(); ++i ) { MObject memberObject; if ( setMembers.getDependNode ( i, memberObject ) ) { if ( dagNode.isChildOf ( memberObject ) ) { return true; } } } } return false; }
MStatus GetSelectedObjectsOfType(MObjectArray & objects, MTypeId & type) { MStatus status; MSelectionList selectionList; if (!(status = MGlobal::getActiveSelectionList(selectionList))) { status.perror("MGlobal::getActiveSelectionList"); return status; } if (!(status = objects.clear())) { status.perror("MObjectArray::clear"); return status; } unsigned int selectionList_length = selectionList.length(&status); if (!status) { status.perror("MSelectionList::length"); return status; } for(unsigned int i = 0; i < selectionList_length; ++i) { //MDagPath dagPath; MObject object; if (!(status = selectionList.getDependNode(i, object))) { status.perror("MSelectionList::getDependNode"); return status; } MObject relative = GetObjectOrParentsOfType(object, type, status); if (!status) { status.perror("GetObjectOrParentsOfType"); return status; } if (relative != MObject::kNullObj) { /* * Make sure it's not already added */ bool contains = false; for(unsigned int i = 0; i < objects.length(); ++i) { if (objects[i] == object) { contains = true; break; } } if (!contains) objects.append(relative); } } return MStatus::kSuccess; }
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; }
MObject getMObjectByName(const MString& name) { MSelectionList sList; MGlobal::getSelectionListByName(name, sList); assert(1==sList.length()); MObject mobj; sList.getDependNode(0, mobj); return mobj; }
AbcWriteJob::AbcWriteJob(const char * iFileName, std::set<double> & iTransFrames, Alembic::AbcCoreAbstract::TimeSamplingPtr iTransTime, const JobArgs & iArgs) { MStatus status; mFileName = iFileName; mBoxIndex = 0; mArgs = iArgs; mTransSamples = 1; if (mArgs.useSelectionList) { bool emptyDagPaths = mArgs.dagPaths.empty(); // get the active selection MSelectionList activeList; MGlobal::getActiveSelectionList(activeList); mSList = activeList; unsigned int selectionSize = activeList.length(); for (unsigned int index = 0; index < selectionSize; index ++) { MDagPath dagPath; status = activeList.getDagPath(index, dagPath); if (status == MS::kSuccess) { unsigned int length = dagPath.length(); while (--length) { dagPath.pop(); mSList.add(dagPath, MObject::kNullObj, true); } if (emptyDagPaths) { mArgs.dagPaths.insert(dagPath); } } } } mTransFrames = iTransFrames; // only needed during creation of the transforms mTransTime = iTransTime; mTransTimeIndex = 0; // should have at least 1 value assert(!mTransFrames.empty()); mFirstFrame = *(mTransFrames.begin()); std::set<double>::iterator last = mTransFrames.end(); last--; mLastFrame = *last; }
void EntityInstanceNode::SelectionChangedCallback( void* clientData ) { MAYA_START_EXCEPTION_HANDLING(); if( !s_ReplaceSelection ) { return; } static bool inFunc = false; if( inFunc ) return; else inFunc = true; MSelectionList list; MGlobal::getActiveSelectionList( list ); MStatus stat; MSelectionList addList; bool added = false; u32 len = list.length(); for( u32 i = 0; i < len; ) { MDagPath path; list.getDagPath( i, path ); MObject entityNode = EntityNodeParent( path ); if( entityNode != MObject::kNullObj ) { added = true; MFnDagNode nodeFn( entityNode ); MDagPath instancePath; nodeFn.getPath( instancePath ); addList.add( instancePath ); list.remove( i ); } else { ++i; } } if( added ) { MGlobal::setActiveSelectionList( list, MGlobal::kReplaceList ); MGlobal::setActiveSelectionList( addList, MGlobal::kAddToList ); } inFunc = false; MAYA_FINISH_EXCEPTION_HANDLING(); }
MStatus pbdSolverCmd::redoIt() { //create solver node MStatus stat; MObject transform = dgMod.createNode("transform"); MObject solver= dgMod.createNode(pbdSolverNode::typeId, transform, &stat); //connect time attribute MPlug plgInTime(solver,pbdSolverNode::time); MItDependencyNodes dnTime(MFn::kTime); MObject time = dnTime.thisNode(); MPlug plgOutTime = MFnDependencyNode(time).findPlug("outTime", false); dgMod.connect(plgOutTime, plgInTime); //connect msattr MSelectionList activeSelect; MGlobal::getActiveSelectionList(activeSelect); int pnum = 0, mnum = 0; for(int i = 0;i < activeSelect.length(); ++i) { MObject tNode; activeSelect.getDependNode(i,tNode); MFnDagNode fnDagNode(tNode); MObject pNode=fnDagNode.child(0); MFnDependencyNode fnNode(pNode); //MString name=fnNode1.name().asChar(); if(fnNode.typeId() == OParticleNode::typeId) { //get solver message attribute from particleNode MPlug s_msg(pNode,OParticleNode::pbd_solver); //get particle message attribute from solverNode MPlug o_msg(solver,pbdSolverNode::orientedParticle); dgMod.connect(o_msg,s_msg); ++pnum; } else if(pNode.apiType()==MFn::kMesh) { MString name=MFnDependencyNode(pNode).name().asChar(); MPlug m_vs=fnNode.findPlug("ogc",false); MPlug s_vs(solver,pbdSolverNode::inMesh); dgMod.connect(m_vs,s_vs); ++mnum; } } if( pnum == 0 ) MGlobal::displayError(" No oriented particles are selected"); if( mnum == 0 ) MGlobal::displayError(" No mesh is selected"); MGlobal::displayInfo("PBD solver is created"); return dgMod.doIt(); }
MStatus particleSystemInfoCmd::nodeFromName(MString name, MObject & obj) { MSelectionList tempList; tempList.add( name ); if ( tempList.length() > 0 ) { tempList.getDependNode( 0, obj ); return MS::kSuccess; } return MS::kFailure; }
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 ); } }
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 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; }
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"); }
// // 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; }
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 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 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<list.length(); i++ ) { list.getDependNode( i, node ); id = MNodeMessage::addAttributeChangedCallback( node, 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 << "MNodeMessage.addCallback failed\n"; } } return stat; }
//----------------------------------------------------------------------------- // Selects all vstAttachment nodes in the scene //----------------------------------------------------------------------------- MStatus CVstAttachmentCmd::DoSelect() { MSelectionList mSelectionList; MDagPath mDagPath; for ( MItDag dagIt; !dagIt.isDone(); dagIt.next() ) { if ( MFnDependencyNode( dagIt.item() ).typeName() == "vstAttachment" ) { dagIt.getPath( mDagPath ); mSelectionList.add( mDagPath, MObject::kNullObj, true ); } } if ( mSelectionList.length() ) { // Save the current selection just in case we want to undo stuff MGlobal::getActiveSelectionList( m_mSelectionList ); MGlobal::setActiveSelectionList( mSelectionList, MGlobal::kReplaceList ); m_undoable = true; } return MS::kSuccess; }
bool GDExporter::GetSelectedMeshTransformPath(MDagPath &transformPath) { MSelectionList currSelection; MGlobal::getActiveSelectionList(currSelection); unsigned int selectionCount = currSelection.length(); MFnMesh* exportingMesh = 0; for(unsigned int selectionIndex = 0; selectionIndex < selectionCount; ++selectionIndex ) { MDagPath currPath; currSelection.getDagPath(selectionIndex, currPath); if( currPath.apiType() != MFn::kTransform ) continue; MFnTransform currTransform(currPath); unsigned int childCount = currTransform.childCount(); for(unsigned int childIndex = 0; childIndex < childCount; ++childIndex) { MObject childObject = currTransform.child(childIndex); if( childObject.apiType() == MFn::kMesh ) { MFnMesh childMesh(childObject); if( childMesh.isIntermediateObject() ) continue; currTransform.getPath(transformPath); return true; } } } return false; }
void IterateSelection() { unsigned int i; MSelectionList list; MDagPath dagpath; MFnDagNode fnnode; MGlobal::getActiveSelectionList(list); for(i = 0; i < list.length(); i++) { list.getDagPath(i, dagpath); fnnode.setObject(dagpath); cout << fnnode.name().asChar() << " of type " << fnnode.typeName().asChar() << " is selected" << endl; cout << "has " << fnnode.childCount() << " children" << endl; //Iterate the children for(int j = 0; j < fnnode.childCount(); j++) { MObject childobj; MFnDagNode fnchild; childobj = fnnode.child(j); fnchild.setObject(childobj); cout << "child " << j << " is a " << fnchild.typeName().asChar() << endl; //MFn::Type type = fnchild.type() //if(fnchild.type() == MFn::kMesh) //DumpMesh(dagpath); //DumpMesh2(dagpath); IterateWorldMeshesInSelection(); } } }
void liqIPRNodeMessage::gatherUpdateObjects(std::vector<MString>& objects) { MStatus status; //get selection list MSelectionList selection; IfMErrorWarn(MGlobal::getActiveSelectionList( selection )); for ( unsigned int i=0; i<selection.length(); i++ ) { MObject node; IfMErrorWarn(selection.getDependNode( i, node )); MFnDependencyNode nodeFn(node, &status); IfMErrorWarn(status); const MString nodeName(nodeFn.name()); objects.push_back(nodeName);//record current node if( isShaderNode(nodeName) ) { onShaderNode(nodeName, objects); } else{ onOtherNode(nodeName, objects); } } //add current camera shape node MStringArray cameraShapeFullPaths; IfMErrorWarn(MGlobal::executeCommand("string $cam = `getAttr liquidGlobals.renderCamera`; ls -long $cam;", cameraShapeFullPaths)); objects.push_back(cameraShapeFullPaths[0]); //add current camera transform node }
//-***************************************************************************** MStatus AbcExportSelected( const Parameters &iConfig ) { // Abc::Init(); //-************************************************************************* // CREATE SELECTION LIST //-************************************************************************* MSelectionList slist; MGlobal::getActiveSelectionList( slist ); if ( slist.length() == 0 ) { MGlobal::displayError( "Nothing selected." ); return MS::kFailure; } //-************************************************************************* // CREATE THE ARCHIVE //-************************************************************************* if ( iConfig.fileName == "UNSPECIFIED_FILE_NAME.abc" || iConfig.fileName == "" ) { MGlobal::displayError( "No filename specified." ); return MStatus::kFailure; } // Create the time sampling. Abc::TimeSamplingType tSmpType; if ( iConfig.endFrame > iConfig.startFrame ) { tSmpType = Abc::TimeSamplingType( // Increment, in seconds, between samples. ( Abc::chrono_t ) MTime( 1.0, MTime::uiUnit() ).as( MTime::kSeconds ) ); } // Get FPS Abc::chrono_t fps = MTime( 1.0, MTime::kSeconds ).as( MTime::uiUnit() ); Top top( iConfig.fileName, tSmpType, fps ); std::cout << "AlembicSimpleAbcExport: Opened Alembic Archive: " << top.getName() << " for writing." << std::endl; // Build comments std::string comments = "AlembicSimpleAbcExport v0.1.1"; comments += "\n"; MString exportedFromStr = "(Exported from " + MFileIO::currentFile() + ")"; comments += exportedFromStr.asChar(); comments += "\n"; // top.setComments( comments ); //-********************************************************************* // BUILD TREE OF NODE:OBJECT PAIRS TO EXPORT //-********************************************************************* // Create the factory Factory factory( iConfig ); for ( MItSelectionList liter( slist ); !liter.isDone(); liter.next() ) { MDagPath dagPath; MObject component; liter.getDagPath( dagPath, component ); // This will skip nodes we've already visited. HAVE NO // FEAR. factory.makeTree( top, dagPath, 1000000, tSmpType ); } std::cout << "AlembicSimpleAbcExport: Created DAG Tree to export." << std::endl; //-********************************************************************* // EXPORT SAMPLES PER FRAME //-********************************************************************* // Loop over time MComputation computation; computation.beginComputation(); for ( int frame = iConfig.startFrame; frame <= iConfig.endFrame; ++frame ) { // Get a time. MTime thisTime( ( double )frame, MTime::uiUnit() ); // Set the time. MAnimControl::setCurrentTime( thisTime ); // Get the chrono and the index Abc::index_t frameIndex = ( Abc::index_t )( frame - iConfig.startFrame ); Abc::chrono_t frameTime = ( Abc::chrono_t )thisTime.as( MTime::kSeconds ); // Is this necessary to force an eval? Sometimes? // MGlobal::viewFrame( t ); // M3dView currentView = M3dView::active3dView(); // currentView.refresh( true, true, true ); // Write the frame. top.writeSample( Abc::OSampleSelector( frameIndex, frameTime ) ); std::cout << "AlembicSimpleAbcExport: Wrote frame: " << frame << std::endl; if ( computation.isInterruptRequested() ) { break; } } top.close(); computation.endComputation(); // H5close(); std::cout << "AlembicSimpleAbcExport: Closed Archive." << std::endl; return MS::kSuccess; }