本文整理汇总了Python中maya.cmds.ls方法的典型用法代码示例。如果您正苦于以下问题:Python cmds.ls方法的具体用法?Python cmds.ls怎么用?Python cmds.ls使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maya.cmds
的用法示例。
在下文中一共展示了cmds.ls方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: shape_from_element
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def shape_from_element(element):
"""Return shape of given 'element'
Supports components, meshes, and surfaces
"""
try:
# Get either shape or transform, based on element-type
node = cmds.ls(element, objectsOnly=True)[0]
except:
cmds.warning("Could not find node in %s" % element)
return None
if cmds.nodeType(node) == 'transform':
try:
return cmds.listRelatives(node, shapes=True)[0]
except:
cmds.warning("Could not find shape in %s" % element)
return None
else:
return node
示例2: maintained_selection
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def maintained_selection():
"""Maintain selection during context
Example:
>>> scene = cmds.file(new=True, force=True)
>>> node = cmds.createNode("transform", name="Test")
>>> cmds.select("persp")
>>> with maintained_selection():
... cmds.select("Test", replace=True)
>>> "Test" in cmds.ls(selection=True)
False
"""
previous_selection = cmds.ls(selection=True)
try:
yield
finally:
if previous_selection:
cmds.select(previous_selection,
replace=True,
noExpand=True)
else:
cmds.select(clear=True)
示例3: lsattr
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def lsattr(attr, value=None):
"""Return nodes matching `key` and `value`
Arguments:
attr (str): Name of Maya attribute
value (object, optional): Value of attribute. If none
is provided, return all nodes with this attribute.
Example:
>> lsattr("id", "myId")
["myNode"]
>> lsattr("id")
["myNode", "myOtherNode"]
"""
if value is None:
return cmds.ls("*.%s" % attr,
recursive=True,
objectsOnly=True,
long=True)
return lsattrs({attr: value})
示例4: dpLoadBSNode
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def dpLoadBSNode(self, *args):
""" Load selected object as blendShapeNode
"""
selectedList = cmds.ls(selection=True)
if selectedList:
if cmds.objectType(selectedList[0]) == "blendShape":
cmds.textField(self.bsNodeTextField, edit=True, text=selectedList[0])
self.dpLoadBSTgtList(selectedList[0])
self.bsNode = selectedList[0]
elif cmds.objectType(selectedList[0]) == "transform":
meshList = cmds.listRelatives(selectedList[0], children=True, shapes=True, noIntermediate=True, type="mesh")
if meshList:
bsNodeList = cmds.listConnections(meshList[0], type="blendShape")
if bsNodeList:
self.dpLoadBSTgtList(bsNodeList[0])
self.bsNode = bsNodeList[0]
else:
mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";")
else:
mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";")
else:
mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";")
else:
mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";")
示例5: dpLoadGeoToAttach
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def dpLoadGeoToAttach(self, geoName=None, geoFromUI=None, *args):
""" Load selected object a geometry to attach rivet.
"""
if geoName:
selectedList = [geoName]
elif geoFromUI:
selectedList = [cmds.textField(self.geoToAttachTF, query=True, text=True)]
else:
selectedList = cmds.ls(selection=True)
if selectedList:
if self.dpCheckGeometry(selectedList[0]):
self.geoToAttach = selectedList[0]
cmds.textField(self.geoToAttachTF, edit=True, text=self.geoToAttach)
self.dpLoadUVSet(self.geoToAttach)
else:
mel.eval("warning \"Select a geometry in order use it to attach rivets, please.\";")
示例6: pasteAttr
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def pasteAttr(self, destinationList=False, verbose=False, *args):
""" Get to destination list and set the dictionary values on them.
"""
# getting destinationList:
if not destinationList:
destinationList = cmds.ls(selection=True, long=True)
if destinationList and self.attrValueDic:
# set dic values to destinationList:
for destItem in destinationList:
for attr in self.attrValueDic:
try:
cmds.setAttr(destItem+'.'+attr, self.attrValueDic[attr])
except:
try:
cmds.setAttr(destItem+'.'+attr, self.attrValueDic[attr], type='string')
except:
pass
if verbose:
print self.dpUIinst.langDic[self.dpUIinst.langName]["e016_notPastedAttr"], attr
if verbose:
print self.dpUIinst.langDic[self.dpUIinst.langName]["i126_pastedAttr"]
示例7: findModuleLastNumber
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def findModuleLastNumber(className, typeName):
""" Find the last used number of this type of module.
Return its highest number.
"""
# work with rigged modules in the scene:
numberList = []
guideTypeCount = 0
# list all transforms and find the existing value in them names:
transformList = cmds.ls(selection=False, transforms=True)
for transform in transformList:
if cmds.objExists(transform+"."+typeName):
if cmds.getAttr(transform+"."+typeName) == className:
numberList.append(className)
# try check if there is a masterGrp and get its counter:
if cmds.objExists(transform+".masterGrp") and cmds.getAttr(transform+".masterGrp") == 1:
guideTypeCount = cmds.getAttr(transform+'.dp'+className+'Count')
if(guideTypeCount > len(numberList)):
return guideTypeCount
else:
return len(numberList)
示例8: getOriginedFromDic
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def getOriginedFromDic():
""" List all transforms in the scene, verify if there is an originedFrom string attribute and store it value in a dictionary.
Return a dictionary with originedFrom string as keys and transform nodes as values of these keys.
"""
originedFromDic = {}
allTransformList = cmds.ls(selection=False, type="transform")
if allTransformList:
for transform in allTransformList:
if cmds.objExists(transform+".originedFrom"):
tempOriginedFrom = cmds.getAttr(transform+".originedFrom")
if tempOriginedFrom:
if not ";" in tempOriginedFrom:
originedFromDic[tempOriginedFrom] = transform
else:
tempOriginedFromList = tempOriginedFrom.split(";")
for orignedFromString in tempOriginedFromList:
originedFromDic[orignedFromString] = transform
return originedFromDic
示例9: add_instance
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def add_instance(self):
""" add a source to the instancer and the sporeNode """
selection = cmds.ls(sl=True, l=True)
spore_node = selection.pop(-1)
num_items = cmds.textScrollList('instanceList', numberOfItems=True, q=True)
items = cmds.textScrollList('instanceList', q=True, ai=True)
instances = node_utils.get_instanced_geo(self._node)
for i, obj in enumerate(selection):
# TODO - check if object type is valid
if obj not in instances:
obj_name = '[{}]: {}'.format(i + num_items, obj)
cmds.textScrollList('instanceList', e=1, append=obj_name)
node_utils.connect_to_instancer(obj, self._node)
示例10: context_request
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def context_request(self, widget, action):
if action.text() == 'Delete':
selection = cmds.ls(sl=1, typ='sporeNode')
for geo_wdg, spore_wdgs in self.wdg_tree.iteritems():
for spore_wdg in spore_wdgs:
spore_node = spore_wdg.name
print spore_node
if spore_wdg.is_selected and cmds.objExists(spore_node):
instancer = node_utils.get_instancer(spore_node)
transform = cmds.listRelatives(spore_node, p=True, f=True)
if len(cmds.listRelatives(transform, c=1)) == 1:
cmds.delete((spore_node, transform[0], instancer))
else:
cmds.delete((spore_node, instancer))
selection.remove(spore_node)
cmds.select(selection)
self.refresh_spore()
示例11: move_center_each_object
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def move_center_each_object():
object_mode = cmds.selectMode( q=True, o=True )
cmds.selectMode(o=True)
selection = cmds.ls(sl=True, l=True)
meshes = common.search_polygon_mesh(selection, fullPath=True, nurbs=True)
if not meshes:
return
dummy = common.TemporaryReparent().main(mode='create')
for m in meshes:
cmds.selectMode(o=True)
common.TemporaryReparent().main(m, dummyParent=dummy, mode='cut')
cmds.select(m, r=True)
if not object_mode:
cmds.selectMode(co=True)
move_center2selection()
common.TemporaryReparent().main(m, dummyParent=dummy, mode='parent')
common.TemporaryReparent().main(dummyParent=dummy, mode='delete')
freeze.main(mesh=selection)
cmds.select(selection, r=True)
示例12: reset_actor
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def reset_actor():
from . import sisidebar_sub
sel = cmds.ls(sl=True, l=True)
joints = cmds.ls(sl=True, l=True, type='joint')
if not joints:
joints = []
for s in sel:
if cmds.nodeType(s) == 'KTG_ModelRoot':
child_joints = cmds.ls(cmds.listRelatives(s, ad=True, f=True), l=True, type='joint')
if child_joints:
joints += child_joints
if not sel:
joints = cmds.ls(l=True, type='joint')
for j in joints:
con_info = cmds.connectionInfo(j+'.bindPose', dfs=True)
if not con_info:
continue
con_info = con_info[0]
bind_info = con_info.replace('world', 'xform')
pose = cmds.getAttr(bind_info)
cmds.xform(j, m=pose)
sisidebar_sub.get_matrix()
示例13: ajustSelection
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def ajustSelection(self):
#選択したものからメッシュノードがあるものを取り出し。
#何も選択されていなかったらシーン内のメッシュ全取得
selection = cmds.ls(sl=True)
#print len(selection)
#print selection
if self.popUpMsg:
if len(selection) == 0:
allMeshSel = cmds.confirmDialog(m=self.msg01, t='', b= [self.msg02, self.msg03], db=self.msg02, cb=self.msg03, icn='question',ds=self.msg03)
#print allMeshSel
if allMeshSel == self.msg02:
selection = cmds.ls(type='transform')
else:
if len(selection) == 0:
#print 'process all of mesh'
selection = cmds.ls(type='transform')
#メッシュノードが存在したらリストに加える
return [sel for sel in selection if common.search_polygon_mesh(sel)]
示例14: maya_import
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def maya_import():
temp = __name__.split('.')#nameは自分自身のモジュール名。splitでピリオドごとに3分割。
folderPath = os.path.join(os.getenv('MAYA_APP_DIR'),'Scripting_Files','go')
if not os.path.exists(folderPath):
os.makedirs(os.path.dirname(folderPath+'\\')) # 末尾\\が必要なので注意
#print folderPath
files = os.listdir(folderPath)
if files is not None:
for file in files:
print file
nameSpace = file.replace('.ma', '')
cmds.file(folderPath+'\\'+file, i=True, typ="mayaAscii", iv=True, mnc=False, options="v=0;", pr=True)
#重複マテリアルにファイル名が頭に付与されてしまうのを修正
allMat = cmds.ls(mat=True)
fileName = file.split('.')[0]
for mat in allMat:
if mat.startswith(fileName+'_'):
cmds.rename(mat, mat.replace(fileName+'_', ''))
cmds.inViewMessage( amg='<hl>Go Maya</hl> : Imoprt objects', pos='midCenterTop', fade=True, ta=0.75, a=0.5)
else:
cmds.inViewMessage( amg='<hl>Go Maya</hl> : There is no exported object', pos='midCenterTop', fade=True, ta=0.75, a=0.5)
示例15: freeze
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import ls [as 别名]
def freeze():
cmds.selectMode(o=True)
selection = cmds.ls(sl=True, type = 'transform')
dummy = common.TemporaryReparent().main(mode='create')#モジュールでダミーの親作成
clusterCopy = modeling.ClusterCopy()
for sel in selection:
allChildren = [sel] + cmds.listRelatives(sel, ad=True)#子供を取得して1つのリストにする
polyMesh = common.search_polygon_mesh(allChildren)
if polyMesh:
for mesh in polyMesh:
common.TemporaryReparent().main(mesh, dummyParent=dummy, mode='cut')
defCls = clusterCopy.copy(mesh)
cmds.bakePartialHistory(mesh,pc=True)
if defCls:
clusterCopy.paste(mesh)
common.TemporaryReparent().main(mesh, dummyParent=dummy, mode='parent')#コピーのおわったメッシュの子供を元に戻す
common.TemporaryReparent().main(dummyParent=dummy, mode='delete')#ダミー親削除
cmds.select(selection, r=True)