本文整理汇总了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')
示例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
示例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
#----------------------------------------------------------------------
示例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
#----------------------------------------------------------------------
示例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()
示例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:
示例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
示例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)
示例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
示例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
示例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()
示例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
示例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
示例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
示例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