Python maya.OpenMaya.MDagPath() Examples
The following are 30
code examples of maya.OpenMaya.MDagPath().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
maya.OpenMaya
, or try the search function
.
Example #1
Source File: skin.py From mgear_core with MIT License | 7 votes |
def getGeometryComponents(skinCls): """Get the geometry components from skincluster Arguments: skinCls (PyNode): The skincluster node Returns: dagPath: The dagpath for the components componets: The skincluster componets """ fnSet = OpenMaya.MFnSet(skinCls.__apimfn__().deformerSet()) members = OpenMaya.MSelectionList() fnSet.getMembers(members, False) dagPath = OpenMaya.MDagPath() components = OpenMaya.MObject() members.getDagPath(0, dagPath, components) return dagPath, components
Example #2
Source File: outliner2.py From tutorials with MIT License | 6 votes |
def sortKey(self): """ Computed property that builds a sort key based on a combination of attributes. Allows sorting to consider multiple keys. """ if self.dagObj: dagCopy = om.MDagPath(self.dagObj) try: dagCopy.extendToShape() self.apiType = dagCopy.apiType() except RuntimeError: self.apiType = self.dagObj.apiType() key = '{0}{1}'.format(self.apiType, self.name) return key
Example #3
Source File: skin.py From maya-skinning-tools with GNU General Public License v3.0 | 6 votes |
def getSkinWeights(dag, skinCluster, component): """ Get the skin weights of the original vertex and of its connected vertices. :param OpenMaya.MDagPath dag: :param OpenMayaAnim.MFnSkinCluster skinCluster: :param OpenMaya.MFn.kMeshVertComponent component: :return: skin weights and number of influences :rtype: tuple(OpenMaya.MDoubleArray, int) """ # weights variables weights = OpenMaya.MDoubleArray() # influences variables influenceMSU = OpenMaya.MScriptUtil() influencePTR = influenceMSU.asUintPtr() # get weights skinCluster.getWeights(dag, component, weights, influencePTR) # get num influences num = OpenMaya.MScriptUtil.getUint(influencePTR) return weights, num
Example #4
Source File: utils.py From DeformationLearningSolver with BSD 3-Clause "New" or "Revised" License | 6 votes |
def getDagPathComponents(compList): """ Args: compList (list) Returns: MObject """ currSel = cmds.ls(sl=1, l=1) cmds.select(compList, r=1) selList = om.MSelectionList() om.MGlobal.getActiveSelectionList(selList) dagPath = om.MDagPath() components = om.MObject() selList.getDagPath(0, dagPath, components) cmds.select(cl=1) try: cmds.select(currSel, r=1) except: pass return dagPath, components #----------------------------------------------------------------------
Example #5
Source File: utils.py From DeformationLearningSolver with BSD 3-Clause "New" or "Revised" License | 6 votes |
def getComponent(name): """ Args: name (str) Returns: MOBject """ selList = om.MSelectionList() selList.add (name) dagPath = om.MDagPath() component = om.MObject() selList.getDagPath(0, dagPath, component) return component #----------------------------------------------------------------------
Example #6
Source File: mesh.py From maya-skinning-tools with GNU General Public License v3.0 | 6 votes |
def getNormals(dag): """ Get the average normal in world space of each vertex on the provided mesh. The reason why OpenMaya.MItMeshVertex function has to be used is that the MFnMesh class returns incorrect normal results. :param OpenMaya.MDagPath dag: :return: Normals :rtype: list """ # variables normals = [] iter = OpenMaya.MItMeshVertex(dag) while not iter.isDone(): # get normal data normal = OpenMaya.MVector() iter.getNormal(normal, OpenMaya.MSpace.kWorld) normals.append(normal) iter.next() return normals
Example #7
Source File: skinio.py From cmt with MIT License | 6 votes |
def gather_influence_weights(self, dag_path, components): """Gathers all the influence weights :param dag_path: MDagPath of the deformed geometry. :param components: Component MObject of the deformed components. """ weights = self.__get_current_weights(dag_path, components) influence_paths = OpenMaya.MDagPathArray() influence_count = self.fn.influenceObjects(influence_paths) components_per_influence = weights.length() // influence_count for ii in range(influence_paths.length()): influence_name = influence_paths[ii].partialPathName() # We want to store the weights by influence without the namespace so it is easier # to import if the namespace is different influence_without_namespace = shortcuts.remove_namespace_from_name( influence_name ) self.data["weights"][influence_without_namespace] = [ weights[jj * influence_count + ii] for jj in range(components_per_influence) ]
Example #8
Source File: skin.py From mgear_core with MIT License | 6 votes |
def getCurrentWeights(skinCls, dagPath, components): """Get the skincluster weights Arguments: skinCls (PyNode): The skincluster node dagPath (MDagPath): The skincluster dagpath components (MObject): The skincluster components Returns: MDoubleArray: The skincluster weights """ weights = OpenMaya.MDoubleArray() util = OpenMaya.MScriptUtil() util.createFromInt(0) pUInt = util.asUintPtr() skinCls.__apimfn__().getWeights(dagPath, components, weights, pUInt) return weights ###################################### # Skin Collectors ######################################
Example #9
Source File: mesh.py From maya-skinning-tools with GNU General Public License v3.0 | 6 votes |
def getConnectedVertices(dag, component): """ index -> OpenMaya.MFn.kMeshVertComponent :param OpenMaya.MDagPath dag: :param OpenMaya.MFn.kMeshVertComponent component: :return: Initialized component(s), number of connected vertices :rtype: tuple(OpenMaya.MFn.kMeshVertComponent, int) """ connected = OpenMaya.MIntArray() # get connected vertices iter = OpenMaya.MItMeshVertex(dag, component) iter.getConnectedVertices(connected) # get component of connected vertices component = asComponent(connected) return component, len(connected)
Example #10
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 6 votes |
def getCurveFn(self): inputCurvePlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.inputCurveAttr) curve = getSingleSourceObjectFromPlug(inputCurvePlug) # Get Fn from a DAG path to get the world transformations correctly if curve is not None: path = OpenMaya.MDagPath() trFn = OpenMaya.MFnDagNode(curve) trFn.getPath(path) path.extendToShape() if path.node().hasFn(OpenMaya.MFn.kNurbsCurve): return OpenMaya.MFnNurbsCurve(path) return None # Calculate expected instances by the instancing mode
Example #11
Source File: mesh_utils.py From spore with MIT License | 6 votes |
def get_mesh_fn(target): """ get mesh function set for the given target :param target: dag path of the mesh :return MFnMesh """ if isinstance(target, str) or isinstance(target, unicode): slls = om.MSelectionList() slls.add(target) ground_path = om.MDagPath() slls.getDagPath(0, ground_path) ground_path.extendToShapeDirectlyBelow(0) ground_node = ground_path.node() elif isinstance(target, om.MObject): ground_node = target ground_path = target elif isinstance(target, om.MDagPath): ground_node = target.node() ground_path = target else: raise TypeError('Must be of type str, MObject or MDagPath, is type: {}'.format(type(target))) if ground_node.hasFn(om.MFn.kMesh): return om.MFnMesh(ground_path) else: raise TypeError('Target must be of type kMesh')
Example #12
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def dagPath(self): """Return a om.MDagPath for this node Example: >>> _ = cmds.file(new=True, force=True) >>> parent = createNode("transform", name="Parent") >>> child = createNode("transform", name="Child", parent=parent) >>> path = child.dagPath() >>> str(path) 'Child' >>> str(path.pop()) 'Parent' """ return om.MDagPath.getAPathTo(self._mobject)
Example #13
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def _encodedagpath1(path): """Convert `path` to Maya API 1.0 MObject Arguments: path (str): Absolute or relative path to DAG or DG node Raises: ExistError on `path` not existing """ selectionList = om1.MSelectionList() try: selectionList.add(path) except RuntimeError: raise ExistError("'%s' does not exist" % path) dagpath = om1.MDagPath() selectionList.getDagPath(0, dagpath) return dagpath
Example #14
Source File: outliner3.py From tutorials with MIT License | 6 votes |
def sortKey(self): """ Computed property that builds a sort key based on a combination of attributes. Allows sorting to consider multiple keys. """ if self.dagObj: self.apiType = self.dagObj.apiType() dagCopy = om.MDagPath(self.dagObj) try: dagCopy.extendToShape() self.shapeApiType = dagCopy.apiType() except RuntimeError: self.shapeApiType = om.MFn.kInvalid key = '%s%s%s' % (self.apiType, self.shapeApiType, self.name) return key
Example #15
Source File: spore_context.py From spore with MIT License | 6 votes |
def modify_radius(self): """ modify the brush radius """ delta_x = self.state.last_x - self.state.cursor_x view = window_utils.active_view() cam_dag = om.MDagPath() view.getCamera(cam_dag) cam_node_fn = node_utils.get_dgfn_from_dagpath(cam_dag.fullPathName()) cam_coi = cam_node_fn.findPlug('centerOfInterest').asDouble() step = delta_x * (cam_coi * -0.01) if (self.state.radius + step) >= 0.01: self.state.radius += step else: self.state.radius = 0.01
Example #16
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 5 votes |
def findShadingGroup(self, dagPath): # Search in children first before extending to shape for child in xrange(dagPath.childCount()): childDagPath = OpenMaya.MDagPath() fnDagNode = OpenMaya.MFnDagNode(dagPath.child(child)) fnDagNode.getPath(childDagPath) fnSet = self.findShadingGroup(childDagPath) if fnSet is not None: return fnSet if self.hasShapeBelow(dagPath): dagPath.extendToShape() fnDepNode = OpenMaya.MFnDependencyNode(dagPath.node()) instPlugArray = fnDepNode.findPlug("instObjGroups") instPlugArrayElem = instPlugArray.elementByLogicalIndex(dagPath.instanceNumber()) if instPlugArrayElem.isConnected(): connectedPlugs = OpenMaya.MPlugArray() instPlugArrayElem.connectedTo(connectedPlugs, False, True) if connectedPlugs.length() == 1: sgNode = connectedPlugs[0].node() if sgNode.hasFn(OpenMaya.MFn.kSet): return OpenMaya.MFnSet(sgNode) return None
Example #17
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 5 votes |
def getInputTransformFn(self): inputTransformPlug = self.getInputTransformPlug() transform = getSingleSourceObjectFromPlug(inputTransformPlug) # Get Fn from a DAG path to get the world transformations correctly if transform is not None and transform.hasFn(OpenMaya.MFn.kTransform): path = OpenMaya.MDagPath() trFn = OpenMaya.MFnDagNode(transform) trFn.getPath(path) return OpenMaya.MFnTransform(path) return None
Example #18
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 5 votes |
def getNodeTransformFn(self): dagNode = OpenMaya.MFnDagNode(self.thisMObject()) dagPath = OpenMaya.MDagPath() dagNode.getPath(dagPath) return OpenMaya.MFnDagNode(dagPath.transform())
Example #19
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 5 votes |
def createChildren(self): # List of tuples self.manipCount = 0 self.manipHandleList = [] self.manipIndexCallbacks = {} selectedObjects = OpenMaya.MSelectionList() OpenMaya.MGlobal.getActiveSelectionList(selectedObjects) # Because we need to know the selected object to manipulate, we cannot manipulate various nodes at once... if selectedObjects.length() != 1: return None dagPath = OpenMaya.MDagPath() selectedObjects.getDagPath(0, dagPath) dagPath.extendToShape() nodeFn = OpenMaya.MFnDependencyNode(dagPath.node()) enableManipulators = nodeFn.findPlug(instanceAlongCurveLocator.enableManipulatorsAttr).asBool() # If the node is not using the custom rotation, prevent the user from breaking it ;) if not enableManipulators: return None self.manipCount = nodeFn.findPlug(instanceAlongCurveLocator.curveAxisHandleCountAttr).asInt() for i in xrange(self.manipCount): pointOnCurveManip = self.addPointOnCurveManip("pointCurveManip" + str(i), "pointCurve" + str(i)) discManip = self.addDiscManip("discManip" + str(i), "disc" + str(i)) self.manipHandleList.append((pointOnCurveManip, discManip))
Example #20
Source File: shortcuts.py From cmt with MIT License | 5 votes |
def get_dag_path2(node): """Get the MDagPath of the given node. :param node: Node name :return: Node MDagPath """ selection_list = OpenMaya2.MSelectionList() selection_list.add(node) return selection_list.getDagPath(0)
Example #21
Source File: shortcuts.py From cmt with MIT License | 5 votes |
def get_dag_path(node): """Get the MDagPath of the given node. :param node: Node name :return: Node MDagPath """ selection_list = OpenMaya.MSelectionList() selection_list.add(node) path = OpenMaya.MDagPath() selection_list.getDagPath(0, path) return path
Example #22
Source File: mayasceneviewport.py From cross3d with MIT License | 5 votes |
def _nativeCamera(self): undocumentedPythonFunctionRequirement = om.MDagPath() with ExceptionRouter(): self._nativePointer.getCamera(undocumentedPythonFunctionRequirement) return undocumentedPythonFunctionRequirement.node()
Example #23
Source File: skinio.py From cmt with MIT License | 5 votes |
def __get_geometry_components(self): """Get the MDagPath and component MObject of the deformed geometry. :return: (MDagPath, MObject) """ # Get dagPath and member components of skinned shape fnset = OpenMaya.MFnSet(self.fn.deformerSet()) members = OpenMaya.MSelectionList() fnset.getMembers(members, False) dag_path = OpenMaya.MDagPath() components = OpenMaya.MObject() members.getDagPath(0, dag_path, components) return dag_path, components
Example #24
Source File: skinio.py From cmt with MIT License | 5 votes |
def gather_blend_weights(self, dag_path, components): """Gathers the blendWeights :param dag_path: MDagPath of the deformed geometry. :param components: Component MObject of the deformed components. """ weights = OpenMaya.MDoubleArray() self.fn.getBlendWeights(dag_path, components, weights) self.data["blendWeights"] = [weights[i] for i in range(weights.length())]
Example #25
Source File: skinio.py From cmt with MIT License | 5 votes |
def set_influence_weights(self, dag_path, components): """Sets all the influence weights. :param dag_path: MDagPath of the deformed geometry. :param components: Component MObject of the deformed components. """ influence_paths = OpenMaya.MDagPathArray() influence_count = self.fn.influenceObjects(influence_paths) elements = OpenMaya.MIntArray() fncomp = OpenMaya.MFnSingleIndexedComponent(components) fncomp.getElements(elements) weights = OpenMaya.MDoubleArray(elements.length() * influence_count) components_per_influence = elements.length() for imported_influence, imported_weights in self.data["weights"].items(): imported_influence = imported_influence.split("|")[-1] for ii in range(influence_paths.length()): influence_name = influence_paths[ii].partialPathName() influence_without_namespace = shortcuts.remove_namespace_from_name( influence_name ) if influence_without_namespace == imported_influence: # Store the imported weights into the MDoubleArray for jj in range(components_per_influence): weights.set(imported_weights[elements[jj]], jj * influence_count + ii) break influence_indices = OpenMaya.MIntArray(influence_count) for ii in range(influence_count): influence_indices.set(ii, ii) self.fn.setWeights(dag_path, components, influence_indices, weights, False)
Example #26
Source File: skinio.py From cmt with MIT License | 5 votes |
def set_blend_weights(self, dag_path, components): """Set the blendWeights. :param dag_path: MDagPath of the deformed geometry. :param components: Component MObject of the deformed components. """ elements = OpenMaya.MIntArray() fncomp = OpenMaya.MFnSingleIndexedComponent(components) fncomp.getElements(elements) blend_weights = OpenMaya.MDoubleArray(elements.length()) for i in range(elements.length()): blend_weights.set(self.data["blendWeights"][elements[i]], i) self.fn.setBlendWeights(dag_path, components, blend_weights)
Example #27
Source File: ml_softWeights.py From ml_tools with MIT License | 5 votes |
def getSoftSelectionWeights(): #get selection sel = om.MSelectionList() softSelection = om.MRichSelection() om.MGlobal.getRichSelection(softSelection) softSelection.getSelection(sel) dagPath = om.MDagPath() component = om.MObject() iter = om.MItSelectionList(sel, om.MFn.kMeshVertComponent) weights = {} while not iter.isDone(): iter.getDagPath( dagPath, component ) dagPath.pop() #Grab the parent of the shape node node = dagPath.fullPathName() fnComp = om.MFnSingleIndexedComponent(component) for i in range(fnComp.elementCount()): weight = 1.0 if fnComp.hasWeights(): weight = fnComp.weight(i).influence() weights['{}.vtx[{}]'.format(node, fnComp.element(i))] = weight iter.next() return weights
Example #28
Source File: ml_centerOfMass.py From ml_tools with MIT License | 5 votes |
def getFacesArea(faces): ''' Get the area of a list of mesh faces. ''' total=0 for f in faces: om.MGlobal.clearSelectionList() om.MGlobal.selectByName(f) sList = om.MSelectionList() om.MGlobal.getActiveSelectionList(sList) sIter = om.MItSelectionList(sList, om.MFn.kMeshPolygonComponent) #change1 dagPath = om.MDagPath() component = om.MObject() sIter.getDagPath(dagPath, component) #change2 polyIter = om.MItMeshPolygon(dagPath, component) util = om.MScriptUtil() util.createFromDouble(0.0) ptr = util.asDoublePtr() polyIter.getArea(ptr, om.MSpace.kWorld) area = om.MScriptUtil(ptr).asDouble() total+=area return total
Example #29
Source File: bake_skin_weight.py From SIWeightEditor with MIT License | 5 votes |
def redoIt(self, flash=True): for node, vtxIndices in self.bake_node_id_dict.items(): weights = self.bake_node_weight_dict[node] infIndices = self.bake_node_inf_dict[node] skinFn = self.node_skinFn_dict[node] if MAYA_VER >= 2016: sList = om2.MSelectionList() sList.add(node) meshDag, component = sList.getComponent(0) # 指定の頂点をコンポーネントとして取得する singleIdComp = om2.MFnSingleIndexedComponent() vertexComp = singleIdComp.create(om2.MFn.kMeshVertComponent ) singleIdComp.addElements(vtxIndices) else: sList = om.MSelectionList() sList.add(node) meshDag = om.MDagPath() component = om.MObject() sList.getDagPath(0, meshDag, component) singleIdComp = om.MFnSingleIndexedComponent() vertexComp = singleIdComp.create(om.MFn.kMeshVertComponent ) singleIdComp.addElements(vtxIndices) ##引数(dag_path, MIntArray, MIntArray, MDoubleArray, Normalize, old_weight_undo) #print meshDag, vertexComp , infIndices , weights #print type(infIndices) #print type(vertexComp) skinFn.setWeights(meshDag, vertexComp , infIndices , weights, False) #アンドゥ用ウェイトデータをアップデートする siweighteditor.update_dict(self.redo_node_weight_dict, self.bake_node_id_dict) if flash: if self.ignore_undo:#スライダー制御中のアンドゥ履歴は全無視する return siweighteditor.refresh_window()
Example #30
Source File: bake_skin_weight.py From SIWeightEditor with MIT License | 5 votes |
def undoIt(self): siweighteditor.reverse_dict(self.undo_node_weight_dict, self.bake_node_id_dict) if self.ignore_undo:#スライダー制御中のアンドゥ履歴は全無視する return for node, vtxIndices in self.bake_node_id_dict.items(): weights = self.org_node_weight_dict[node] infIndices = self.bake_node_inf_dict[node] skinFn = self.node_skinFn_dict[node] if MAYA_VER >= 2016: sList = om2.MSelectionList() sList.add(node) meshDag, component = sList.getComponent(0) singleIdComp = om2.MFnSingleIndexedComponent() vertexComp = singleIdComp.create(om2.MFn.kMeshVertComponent ) singleIdComp.addElements(vtxIndices) else: sList = om.MSelectionList() sList.add(node) meshDag = om.MDagPath() component = om.MObject() sList.getDagPath(0, meshDag, component) singleIdComp = om.MFnSingleIndexedComponent() vertexComp = singleIdComp.create(om.MFn.kMeshVertComponent ) singleIdComp.addElements(vtxIndices) ##引数(dag_path, MIntArray, MIntArray, MDoubleArray, Normalize, old_weight_undo) skinFn.setWeights(meshDag, vertexComp , infIndices , weights, False) #アンドゥの度に読み込むと重いからどうしよう。 siweighteditor.refresh_window()