import re
import maya.OpenMaya as OpenMaya
import maya.cmds as cmds
def toMObject(*objects):
sel = OpenMaya.MSelectionList()
for i in objects:
sel.add(i)
out = list()
for i in xrange(sel.length()):
obj = OpenMaya.MObject()
sel.getDependNode(i,obj)
out.append(obj)
return out
def tofullPath(*MObjects):
return [OpenMaya.MFnDagNode(i).fullPathName() for i in MObjects]
def clearRoots(roots):
realRoots = cmds.ls(roots,long = True)
roots = list()
for i in xrange(len(realRoots)):
n = True
for r in xrange(len(roots)):
if roots[r].startswith('%s|' % realRoots[i]):
roots[r] = realRoots[i]
n = False
break
elif realRoots[i].startswith(roots[r]):
n = False
break
if n:
roots.append(realRoots[i])
return roots
def lsObject(roots,type = 'transform',filterName = None,fiterVisibility = True):
'''
roots: root objects name (string list)
type: (string list)
filterName: (string list)
fiterVisibility: if is True, only return the display is window Objects
'''
if isinstance(filterName,basestring):
filterName = [filterName]
if not filterName:
filterName = list()
roots = clearRoots(roots)
allDagNode = list()
if type:
for i in roots:
nodes = cmds.listRelatives(i,allDescendents = True,fullPath = True,type = type)
if nodes:
allDagNode += nodes
nodes = cmds.ls(i,long=True,type = type)
if nodes:
allDagNode += nodes
else:
for i in roots:
nodes = cmds.listRelatives(i,allDescendents = True,fullPath = True)
if nodes:
allDagNode += nodes
nodes = cmds.ls(i,long=True)
if nodes:
allDagNode += nodes
if not filterName and not fiterVisibility:
return allDagNode
filterNode = list()
if fiterVisibility:
trf = cmds.listRelatives(roots,allDescendents = True,fullPath = True,type = 'transform')
if trf:
fiterVis = clearRoots([i for i in trf if not cmds.getAttr('%s.v' % i)])
for i in allDagNode:
if all([not i.startswith('%s|' % f) and not i == f for f in fiterVis]):
filterNode.append(i)
allDagNode = filterNode
if not filterName:
return allDagNode
filterNode = list()
for i in allDagNode:
for f in filterName:
if re.match(r'.*%s.*' % f,i):
filterNode.append(i)
break
return filterNode
def findSameName(*objects):
name_dict = dict()
for i in objects:
long_name = cmds.ls(i,long=True)[0]
name = long_name.rsplit('|',1)
name[-1] = name[-1].split(':')[-1]
long_name = '|'.join(name)
if not name_dict.has_key(long_name):
name_dict[long_name] = list()
name_dict[long_name].append(i)
return [name_dict[i] for i in name_dict if len(name_dict[i])>1]
alembicTool_lsObject
最新推荐文章于 2019-08-14 08:42:00 发布