當前位置: 首頁>>代碼示例>>Python>>正文


Python OpenMaya.MSelectionList方法代碼示例

本文整理匯總了Python中maya.OpenMaya.MSelectionList方法的典型用法代碼示例。如果您正苦於以下問題:Python OpenMaya.MSelectionList方法的具體用法?Python OpenMaya.MSelectionList怎麽用?Python OpenMaya.MSelectionList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在maya.OpenMaya的用法示例。


在下文中一共展示了OpenMaya.MSelectionList方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_mesh_fn

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
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') 
開發者ID:wiremas,項目名稱:spore,代碼行數:27,代碼來源:mesh_utils.py

示例2: getGeometryComponents

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
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 
開發者ID:mgear-dev,項目名稱:mgear_core,代碼行數:19,代碼來源:skin.py

示例3: getComponent

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
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

#---------------------------------------------------------------------- 
開發者ID:WebberHuang,項目名稱:DeformationLearningSolver,代碼行數:18,代碼來源:utils.py

示例4: getDagPathComponents

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
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

#---------------------------------------------------------------------- 
開發者ID:WebberHuang,項目名稱:DeformationLearningSolver,代碼行數:26,代碼來源:utils.py

示例5: _selectionIter

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
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() 
開發者ID:blurstudio,項目名稱:cross3d,代碼行數:18,代碼來源:mayascene.py

示例6: _setNativeSelection

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
def _setNativeSelection(self, selection):
		""" Select the inputed native objects in the scene
			:param selection: <list> [ <PySoftimage.xsi.Object> nativeObject, .. ] || MSelectionList || str || unicode
			:return: <bool> success
		"""
		if isinstance(selection, basestring):
			try:
				om.MGlobal.selectByName(selection)
			except RuntimeError, e:
				if e.message.find('kNotFound') != -1:
					# No objects were selected
					return False
				else:
					# Something is broken. Investigate as needed
					raise
			finally: 
開發者ID:blurstudio,項目名稱:cross3d,代碼行數:18,代碼來源:mayascene.py

示例7: _get_rotation_quaternion

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
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 
開發者ID:matiascodesal,項目名稱:maya-glTF,代碼行數:23,代碼來源:glTFExport.py

示例8: encode

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
def encode(path):
    """Convert relative or absolute `path` to cmdx Node

    Fastest conversion from absolute path to Node

    Arguments:
        path (str): Absolute or relative path to DAG or DG node

    """

    assert isinstance(path, string_types), "%s was not string" % path

    selectionList = om.MSelectionList()

    try:
        selectionList.add(path)
    except RuntimeError:
        raise ExistError("'%s' does not exist" % path)

    mobj = selectionList.getDependNode(0)
    return Node(mobj) 
開發者ID:mottosso,項目名稱:cmdx,代碼行數:23,代碼來源:cmdx.py

示例9: _encode1

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
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 
開發者ID:mottosso,項目名稱:cmdx,代碼行數:23,代碼來源:cmdx.py

示例10: _encodedagpath1

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
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 
開發者ID:mottosso,項目名稱:cmdx,代碼行數:23,代碼來源:cmdx.py

示例11: updateGauge

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
def updateGauge(self, *args, **kwargs):
        """
        updateGauge()

        Checks the current scene selection, and update 
        both the text label, and the gauge progress. 
        """
        sel = om.MSelectionList()
        om.MGlobal.getActiveSelectionList(sel)
        num_selected = sel.length()

        self.text.setText("Selected %d out of %d objects" % (num_selected, self.maxValue))

        progress = float(num_selected) / self.maxValue
        currentVal = self.gauge.value()

        # animate from our current value, to our new value
        anim = self._value_animator
        anim.setStartValue(currentVal)
        anim.setEndValue(progress)
        anim.start() 
開發者ID:justinfx,項目名稱:tutorials,代碼行數:23,代碼來源:mayaGauge2.py

示例12: asMObjectOld

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
def asMObjectOld( otherMobject ):
    '''
    tries to cast the given obj to an mobject - it can be string
    Taken from zoo.
    '''
    if isinstance( otherMobject, basestring ):
        sel = maya.OpenMaya.MSelectionList()
        sel.add( otherMobject )
        
        if '.' in otherMobject:
            plug = maya.OpenMaya.MPlug()
            sel.getPlug( 0, plug )
            tmp = plug.asMObject()
            tmp.__MPlug__ = plug
        else:
            tmp = maya.OpenMaya.MObject()
            sel.getDependNode( 0, tmp )

        return tmp

    if isinstance( otherMobject, (maya.OpenMaya.MObject, maya.OpenMaya.MObjectHandle) ):
        return otherMobject 
開發者ID:patcorwin,項目名稱:fossil,代碼行數:24,代碼來源:capi.py

示例13: toMObject

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
def toMObject(node):
    """
    Convert a node into a OpenMaya.MObject.

    :param str node:
    :return: MObject of parsed node
    :rtype: OpenMaya.MObject
    """
    selectionList = OpenMaya.MSelectionList()
    selectionList.add(node)
    obj = OpenMaya.MObject()
    selectionList.getDependNode(0, obj)
    
    return obj 
開發者ID:robertjoosten,項目名稱:maya-spline-ik,代碼行數:16,代碼來源:api.py

示例14: parse_args

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
def parse_args(self, args):
        """ parse args """


        arg_data = om.MArgDatabase(self.syntax(), args)

        if arg_data.isFlagSet(k_name_flag):
            self.name = arg_data.getFlagArgument(k_name_flag, 0)

        selection = om.MSelectionList()
        arg_data.getObjects(selection)

        #  # check if we got at least on item
        if selection.length() == 0:
            self.logger.error('Spore Command failed: Nothing Selected')
            return False

        for i in xrange(selection.length()):
            dag_path = om.MDagPath()
            selection.getDagPath(i, dag_path)

            # get target
            if i == 0:

                try:
                    dag_path.extendToShape()
                except RuntimeError:
                    self.logger.error('Spore Command failed: Object has more than one shape')
                    return False

                if dag_path.hasFn(om.MFn.kMesh):
                    self.target = dag_path.node()
                else:
                    self.logger.error('Spore Command failed: Object is not of type kMesh')
                    return False

            # get source
            else:
                self.source.append(dag_path.node())

        return True 
開發者ID:wiremas,項目名稱:spore,代碼行數:43,代碼來源:spore_command.py

示例15: get_mobject_from_name

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MSelectionList [as 別名]
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 
開發者ID:wiremas,項目名稱:spore,代碼行數:12,代碼來源:node_utils.py


注:本文中的maya.OpenMaya.MSelectionList方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。