本文整理汇总了Python中maya.api.OpenMaya.MSelectionList方法的典型用法代码示例。如果您正苦于以下问题:Python OpenMaya.MSelectionList方法的具体用法?Python OpenMaya.MSelectionList怎么用?Python OpenMaya.MSelectionList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maya.api.OpenMaya
的用法示例。
在下文中一共展示了OpenMaya.MSelectionList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cloneMeshs
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MSelectionList [as 别名]
def cloneMeshs(meshPaths):
cloneMeshPaths = []
cloneGroup = cmds.group(empty = True, world = True, name = 'ssdsResult')
cloneGroupSL = om.MGlobal.getSelectionListByName(cloneGroup)
cloneGroupFn = om.MFnTransform(cloneGroupSL.getDagPath(0))
for path in meshPaths:
mesh = om.MFnMesh(path)
meshName = om.MFnDagNode(mesh.parent(0)).name()
cloneMeshName = 'ssds:' + meshName
sl = om.MSelectionList();
sl.clear()
sl.add(path)
om.MGlobal.setActiveSelectionList(sl)
cmds.duplicate(returnRootsOnly = True, name = cloneMeshName, renameChildren = True)
cmds.parent(cloneMeshName, cloneGroup)
cmds.setAttr(cloneMeshName + '.inheritsTransform', False)
cloneMeshSL = om.MGlobal.getSelectionListByName(cloneMeshName)
cloneMeshPath = cloneMeshSL.getDagPath(0)
cloneMeshPath.extendToShape()
cloneMeshPaths.append(cloneMeshPath)
return cloneMeshPaths, cloneGroup
示例2: bakeJointMotion
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MSelectionList [as 别名]
def bakeJointMotion(skinJoints, skinMatrix):
asl = om.MSelectionList()
for sj in skinJoints:
asl.add(sj.path)
om.MGlobal.setActiveSelectionList(asl)
startTime = oma.MAnimControl.animationStartTime()
endTime = oma.MAnimControl.animationEndTime()
frame = 0
ctime = startTime
oma.MAnimControl.setCurrentTime(ctime)
while ctime <= endTime:
oma.MAnimControl.setCurrentTime(ctime)
for jid, sj in enumerate(skinJoints):
m = om.MMatrix(np.dot(sj.bindPose, skinMatrix[jid, frame]).tolist())
m = om.MTransformationMatrix(m)
om.MFnTransform(sj.path).setTransformation(m)
cmds.setKeyframe()
frame = frame + 1
ctime = ctime + 1
oma.MAnimControl.setCurrentTime(startTime)
示例3: encode
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.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)
示例4: _encode1
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.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
示例5: _encodedagpath1
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.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
示例6: flattenSelectionList
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MSelectionList [as 别名]
def flattenSelectionList(self, selList):
flatList = om.MSelectionList()
selIter = om.MItSelectionList(selList)
while not selIter.isDone():
obj = selIter.getDependNode()
# if its a DAG node
if selIter.itemType() == 0:
if selIter.hasComponents():
flatList.add(selIter.getComponent())
# just add it to the list if it's a dag object
elif obj.hasFn(om.MFn.kDagNode):
flatList.add(selIter.getDagPath())
# if its a set recursive call with set contents
elif obj.hasFn(om.MFn.kSet):
flatList.merge(self.flattenSelectionList(om.MFnSet(obj).getMembers(False)))
selIter.next()
return flatList
# attached to all cameras found on plugin launch, removes onions when the camera moves
# but only on user input. animated cameras are not affected
示例7: created_event
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MSelectionList [as 别名]
def created_event(self):
'''
Create user events for attribute changes and node renames.
'''
sel_list = om2.MSelectionList()
sel_list.add(self.node.name())
m_obj = sel_list.getDependNode(0)
if self.uuid not in self.events:
# Attribute
attribute_callback = om2.MNodeMessage.addAttributeChangedCallback(m_obj, self._attribute_changed)
om2.MUserEventMessage.registerUserEvent(self.attr_user_event)
# Name
name_callback = om2.MNodeMessage.addNameChangedCallback(m_obj, self._name_changed)
om2.MUserEventMessage.registerUserEvent(self.name_user_event)
self.events[self.uuid] = {self.attr_user_event, self.name_user_event}
self.callbacks[self.uuid] = {attribute_callback, name_callback}
示例8: undoIt
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MSelectionList [as 别名]
def undoIt(self):
# If we have nothing to undo, lets skip our logic
if not self.__undoStack:
return
# Then we pop the last item, which is the most recent, off the end of our undoStack
translations = self.__undoStack.pop()
# If this was empty, then don't do anything
if not translations:
return
# Finally we need to reconstruct our selection and set the transforms back
# We make an empty selection list
slist = om.MSelectionList()
# Then lets loop through our data
for i, node in enumerate(translations):
# We'll add the item to our selection list
slist.add(node)
# And then get back its dagPath
node = slist.getDagPath(i)
# We use that to construct an MFnTransform
tranFn = om.MFnTransform(node)
# And use that to set its translation back to our cached value
tranFn.setTranslation(translations[node.partialPathName()], om.MSpace.kWorld)
示例9: asMObjectOld
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.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
示例10: getMObject
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MSelectionList [as 别名]
def getMObject(node):
"""get the mobject of any name provided, so it can have cb's assined to it
Args:
node (str): of node
Returns:
om.MObject: MOBJECT
"""
mSel = om.MSelectionList()
mSel.add(node)
return mSel.getDependNode(0)
# types of callbacks managed --------------------------------------------------
示例11: bindToSkin
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MSelectionList [as 别名]
def bindToSkin(meshPaths, skinIndex, skinWeight,
skinJnts, numMaxInfluences):
asl = om.MSelectionList()
asl.clear()
jntNames = [sj.name for sj in skinJnts]
for sj in skinJnts:
m = om.MMatrix(sj.bindPose.tolist())
m = om.MTransformationMatrix(m)
om.MFnTransform(sj.path).setTransformation(m)
asl.add(sj.path)
offset = 0
for meshPath in meshPaths:
mesh = om.MFnMesh(meshPath)
sl = om.MSelectionList(asl)
sl.add(meshPath)
om.MGlobal.setActiveSelectionList(sl)
meshName = om.MFnDagNode(mesh.parent(0)).name()
skinName = cmds.skinCluster(maximumInfluences = numMaxInfluences,
name = meshName + 'Cluster',
toSelectedBones = True)[0]
skinObj = om.MGlobal.getSelectionListByName(skinName).getDependNode(0)
skin = oma.MFnSkinCluster(skinObj)
vertexIndices = om.MIntArray(mesh.numVertices, 0)
for i in xrange(mesh.numVertices):
vertexIndices[i] = i
singleIndexedComp = om.MFnSingleIndexedComponent()
vertexComp = singleIndexedComp.create(om.MFn.kMeshVertComponent)
singleIndexedComp.addElements(vertexIndices)
infDags = skin.influenceObjects()
numInfDags = len(infDags)
infIndices = om.MIntArray(numInfDags, 0)
for i in xrange(numInfDags):
infIndices[i] = i
weights = om.MDoubleArray(mesh.numVertices * numInfDags, 0)
for v in xrange(mesh.numVertices):
for j, w in zip(skinIndex[offset + v], skinWeight[offset + v]):
if j >= 0:
weights[v * numInfDags + j] = w
skin.setWeights(meshPath, vertexComp, infIndices, weights)
offset += mesh.numVertices
skin.findPlug('deformUserNormals', True).setBool(False)
示例12: remove
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MSelectionList [as 别名]
def remove(self, members):
mobj = _encode1(self.name(namespace=True))
selectionList = om1.MSelectionList()
if not isinstance(members, (tuple, list)):
selectionList.add(members.path())
else:
for member in members:
selectionList.add(member.path())
fn = om1.MFnSet(mobj)
fn.removeMembers(selectionList)
示例13: objExists
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MSelectionList [as 别名]
def objExists(obj):
if isinstance(obj, (Node, Plug)):
obj = obj.path()
try:
om.MSelectionList().add(obj)
except RuntimeError:
return False
else:
return True
# PEP08
示例14: removeSelectedOnion
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MSelectionList [as 别名]
def removeSelectedOnion(self):
selList = om.MGlobal.getActiveSelectionList()
if not selList.isEmpty():
self.mOnionObjectBuffer.merge(selList, om.MSelectionList.kRemoveFromList)
self.mOnionObjectList = self.flattenSelectionList(self.mOnionObjectBuffer)
self.rotOnions()
#
示例15: removeOnionObject
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MSelectionList [as 别名]
def removeOnionObject(self, dagPath):
tmpList = om.MSelectionList()
tmpList.add(dagPath)
self.mOnionObjectBuffer.merge(tmpList, om.MSelectionList.kRemoveFromList)
self.mOnionObjectList = self.flattenSelectionList(self.mOnionObjectBuffer)
self.rotOnions()
#