Python maya.OpenMaya.MObject() Examples
The following are 30
code examples of maya.OpenMaya.MObject().
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: mayascenewrapper.py From cross3d with MIT License | 6 votes |
def _getShapeNode(cls, nativeObject): """ A Maya Helper that returns the first shape node of the provided transform node. If no shape node exists the nativeObject is returned. Args: nativeObject (OpenMaya.MObject): The MObject to get the first shape node from. Returns: OpenMaya.MObject: The first shape node of the transform or the passed in object. """ if nativeObject.apiType() == om.MFn.kTransform: path = om.MDagPath.getAPathTo(nativeObject) numShapes = om.MScriptUtil() numShapes.createFromInt(0) numShapesPtr = numShapes.asUintPtr() path.numberOfShapesDirectlyBelow(numShapesPtr) if om.MScriptUtil(numShapesPtr).asUint(): # TODO: Should this return the last shape, instead of the first? path.extendToShapeDirectlyBelow(0) return path.node() return nativeObject
Example #3
Source File: mayascene.py From cross3d with MIT License | 6 votes |
def _selectionIter(cls): """ A Maya Helper that returns a iterator of maya objects currently selected. """ # Create object named selection and type - SelectionList selection = om.MSelectionList() # Fill variable "selection" with list of selected objects om.MGlobal.getActiveSelectionList(selection) # Create iterator through list of selected object selection_iter = om.MItSelectionList(selection) # Loop though iterator objects while not selection_iter.isDone(): obj = om.MObject() selection_iter.getDependNode(obj) yield obj selection_iter.next()
Example #4
Source File: mayascene.py From cross3d with MIT License | 6 votes |
def _objectsOfMTypeIter(cls, objectType): """ Maya Helper that returns a iterator of maya objects filtered by objectType. :param objectType: A enum value used to identify objects. .. seeAlso.. SceneObject._abstractToNativeObjectType """ if not isinstance(objectType, (tuple, list)): objectType = [objectType] for oType in objectType: # Create iterator traverse all camera nodes oIter = om.MItDependencyNodes(oType) # Loop though iterator objects while not oIter.isDone(): # oIter.thisNode() points to current MObject in iterator yield oIter.thisNode() oIter.next() #-------------------------------------------------------------------------------- # cross3d private methods #--------------------------------------------------------------------------------
Example #5
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def createNode(self, type, name=None, parent=None): parent = parent._mobject if parent else om.MObject.kNullObj try: mobj = self._modifier.createNode(type, parent) except TypeError: raise TypeError("'%s' is not a valid node type" % type) template = self._opts["template"] if name or template: name = (template or "{name}").format( name=name or "", type=type, index=self._index, ) self._modifier.renameNode(mobj, name) return DagNode(mobj, exists=False, modifier=self)
Example #6
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def _encode1(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) mobject = om1.MObject() selectionList.getDependNode(0, mobject) return mobject
Example #7
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 #8
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 #9
Source File: mayascenewrapper.py From cross3d with MIT License | 6 votes |
def _getchildShapeNodes(cls, nativeObject): """ A Maya helper that returns a generator of all shape nodes for the provided transform node. Args: nativeObject (OpenMaya.MObject): The object to get the shape nodes of. """ if nativeObject.apiType() == om.MFn.kTransform: path = om.MDagPath.getAPathTo(nativeObject) numShapes = om.MScriptUtil() numShapes.createFromInt(0) numShapesPtr = numShapes.asUintPtr() path.numberOfShapesDirectlyBelow(numShapesPtr) for index in range(om.MScriptUtil(numShapesPtr).asUint()): p = om.MDagPath.getAPathTo(nativeObject) p.extendToShapeDirectlyBelow(index) yield p.node()
Example #10
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 #11
Source File: mayascenewrapper.py From cross3d with MIT License | 6 votes |
def _getTransformNode(cls, nativeObject): """ A Maya Helper that returns the first transform node of the provided shape node. The nativeObject is returned if the nativeObject is a transform node. :param nativeObject: The OpenMaya.MObject to get the transform node of :return: OpenMaya.MObject """ with ExceptionRouter(): # If its not a dag object, there is no transform to return use the nativeObject if not cls._isDagNode(nativeObject): # The world node doesn't play well with the getting transform code. return nativeObject path = om.MDagPath.getAPathTo(nativeObject) newPointer = path.transform() if newPointer != nativeObject: return newPointer return nativeObject
Example #12
Source File: skinio.py From cmt with MIT License | 6 votes |
def __init__(self, skin_cluster): """Constructor""" self.node = skin_cluster self.shape = cmds.listRelatives( cmds.deformer(skin_cluster, q=True, g=True)[0], parent=True, path=True )[0] # Get the skinCluster MObject self.mobject = shortcuts.get_mobject(self.node) self.fn = OpenMayaAnim.MFnSkinCluster(self.mobject) self.data = { "weights": {}, "blendWeights": [], "name": self.node, "shape": self.shape, }
Example #13
Source File: node_utils.py From spore with MIT License | 6 votes |
def get_mobject_from_name(name): """ get mObject from a given dag-path :param name : the name or dag-path to a shapenode to return a mObject to """ sl = om.MSelectionList() if not cmds.objExists(name): raise RuntimeError('Object does not exist: {}'.format(name)) om.MGlobal.getSelectionListByName(name, sl) node = om.MObject() sl.getDependNode(0, node) return node
Example #14
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 #15
Source File: glTFExport.py From maya-glTF with MIT License | 6 votes |
def _get_rotation_quaternion(self): obj=OpenMaya.MObject() #make a object of type MSelectionList sel_list=OpenMaya.MSelectionList() #add something to it #you could retrieve this from function or the user selection sel_list.add(self.maya_node) #fill in the MObject sel_list.getDependNode(0,obj) #check if its a transform if (obj.hasFn(OpenMaya.MFn.kTransform)): quat = OpenMaya.MQuaternion() #then we can add it to transfrom Fn #Fn is basically the collection of functions for given objects xform=OpenMaya.MFnTransform(obj) xform.getRotation(quat) # glTF requires normalize quat quat.normalizeIt() py_quat = [quat[x] for x in range(4)] return py_quat
Example #16
Source File: sticker.py From NodeSticker with MIT License | 5 votes |
def _parse_nodes(target): """Internal function for getting MFnDependencyNode""" mfn_nodes = list() sel_list = oldOm.MSelectionList() for path in target: sel_list.add(path) for i in range(len(target)): mobj = oldOm.MObject() sel_list.getDependNode(i, mobj) mfn_nodes.append(oldOm.MFnDependencyNode(mobj)) return mfn_nodes
Example #17
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 5 votes |
def object(self): """Return MObject of this node""" return self._mobject
Example #18
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 #19
Source File: pushDeformer.py From AdvancedPythonForMaya with GNU General Public License v3.0 | 5 votes |
def getInputMesh(self, data, geomIdx): # To get the mesh we need to check the input of the node inputHandle = data.outputArrayValue(inputAttr) inputHandle.jumpToElement(geomIdx) # Once we have the input handle, we get its values, then find the children mesh and get it as a mesh MObject mesh = inputHandle.outputValue().child(inputGeomAttr).asMesh() return mesh
Example #20
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 5 votes |
def __eq__(self, other): """MObject supports this operator explicitly""" try: # Better to ask forgivness than permission return self._mobject == other._mobject except AttributeError: return str(self) == str(other)
Example #21
Source File: benchmark.py From tutorials with MIT License | 5 votes |
def testPyApi(): start = time.time() # creating the helix via the cmds module, for consistency # in the helix object and number of vertices helix = cmds.polyHelix(**HELIX_OPTS) pHelix = helix[0] sel = OpenMaya.MSelectionList() node = OpenMaya.MObject() sel.add(pHelix) sel.getDependNode( 0, node ) vector = OpenMaya.MVector() iter = OpenMaya.MItMeshVertex(node) while not iter.isDone(): vector.x = RAND.uniform(LOW, HIGH) iter.translateBy(vector) iter.next() OpenMaya.MGlobal.deleteNode(node) end = time.time() return end-start
Example #22
Source File: swingtwist.py From cmt with MIT License | 5 votes |
def __init__(self): OpenMayaMPx.MPxCommand.__init__(self) self._name = "" self._node_mobject = OpenMaya.MObject() self._dgmod = OpenMaya.MDGModifier()
Example #23
Source File: sticker.py From NodeSticker with MIT License | 5 votes |
def reveal(): """Reveal custom icon from previous saved scene Can use with scene open callback for auto display custom icon saved from previous session. """ sel_list = oldOm.MSelectionList() ns_list = [""] + oldOm.MNamespace.getNamespaces(":", True) for ns in ns_list: if ns in (":UI", ":shared"): continue try: sel_list.add(ns + ":*." + ICON_ATTRIBUTE) except RuntimeError: pass for i in range(sel_list.length()): mobj = oldOm.MObject() sel_list.getDependNode(i, mobj) node = oldOm.MFnDependencyNode(mobj) plug = node.findPlug(ICON_ATTRIBUTE) icon_path = plug.asString() try: node.setIcon(os.path.expandvars(icon_path)) except RuntimeError: pass
Example #24
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 #25
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 5 votes |
def __init__(self): self.compound = OpenMaya.MObject() self.x = OpenMaya.MObject() self.y = OpenMaya.MObject() self.z = OpenMaya.MObject()
Example #26
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 5 votes |
def __init__(self): self.compound = OpenMaya.MObject() self.parameter = OpenMaya.MObject() self.angle = OpenMaya.MObject() # The angle over the tangent axis # Legacy attributes to support backward compatibility
Example #27
Source File: instanceAlongCurve.py From instanceAlongCurve with MIT License | 5 votes |
def __init__(self): self.ramp = OpenMaya.MObject() # normalized ramp self.rampOffset = OpenMaya.MObject() # evaluation offset for ramp self.rampAxis = OpenMaya.MObject() # ramp normalized axis self.rampAmplitude = OpenMaya.MObject() # ramp amplitude self.rampRandomAmplitude = OpenMaya.MObject() # ramp random amplitude self.rampRepeat = OpenMaya.MObject() # Simple container class for compound vector attributes
Example #28
Source File: shortcuts.py From cmt with MIT License | 5 votes |
def get_mobject(node): """Get the MObject of the given node. :param node: Node name :return: Node MObject """ selection_list = OpenMaya.MSelectionList() selection_list.add(node) mobject = OpenMaya.MObject() selection_list.getDependNode(0, mobject) return mobject
Example #29
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 #30
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())]