本文整理汇总了Python中maya.cmds.listRelatives函数的典型用法代码示例。如果您正苦于以下问题:Python listRelatives函数的具体用法?Python listRelatives怎么用?Python listRelatives使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了listRelatives函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copyCrvShape
def copyCrvShape():
sel = mc.ls(sl = True)
if len(sel)>1:
crvShape = mc.listRelatives(sel[0] , s = True)
crvDegree = mc.getAttr(crvShape[0]+'.degree')
crvSpans = mc.getAttr(crvShape[0]+'.spans')
crvCvs = crvDegree + crvSpans
for j in range(0,crvCvs+1):
pos = mc.xform(sel[0] + '.cv[ '+str(j)+ ']' , q = True , os = True , t = True )
for i in range(0,len(sel)):
if i == 0:
continue
else :
mc.xform(sel[i] + '.cv[ '+str(j)+ ']' , os = True , t = pos )
else :
searchQuery = mc.textField('searchUI' ,q = True ,tx = True)
raplaceQuery = mc.textField('replaceUI' ,q = True ,tx = True)
newCrv = sel[0].replace(searchQuery,raplaceQuery)
crvShape = mc.listRelatives(sel[0] , s = True)
crvDegree = mc.getAttr(crvShape[0]+'.degree')
crvSpans = mc.getAttr(crvShape[0]+'.spans')
crvCvs = crvDegree + crvSpans
for j in range(0,crvCvs+1):
pos = mc.xform(sel[0] + '.cv[ '+str(j)+ ']' , q = True , ws = True , t = True )
mc.xform(newCrv + '.cv[ '+str(j)+ ']' , ws = True , t = (-pos[0],pos[1],pos[2]) )
示例2: listIntermediates
def listIntermediates(geo):
'''
Return a list of intermediate shapes under a transform parent
@param geo: Transform to list intermediate shapes for
@type geo: str
'''
# Checks
if not mc.objExists(geo):
raise Exception('Object "'+geo+'" does not exist!!')
if isShape(geo):
geo = mc.listRelatives(geo,p=True,pa=True)[0]
# Get Non Intermediate Shapes
shapes = mc.listRelatives(geo,s=True,ni=True,pa=True)
# Get All Shapes
allShapes = mc.listRelatives(geo,s=True,pa=True)
# Get Intermediate Shapes
if not allShapes: return []
if not shapes: return allShapes
intShapes = list(set(allShapes) - set(shapes))
# Return Result
return intShapes
示例3: getShapes
def getShapes(geo,nonIntermediates=True,intermediates=True):
'''
Return a list of shapes under a transform parent
@param geo: Transform to list shapes for
@type geo: str
@param nonIntermediates: List non intermediate shapes
@type nonIntermediates: bool
@param intermediates: List intermediate shapes
@type intermediates: bool
'''
# Checks
if not mc.objExists(geo):
raise Exception('Object "'+geo+'" does not exist!!')
if isShape(geo):
geo = mc.listRelatives(geo,p=True,pa=True)[0]
# Get Shapes
shapes = []
if nonIntermediates:
nonIntShapes = mc.listRelatives(geo,s=True,ni=True,pa=True)
if nonIntShapes: shapes.extend(nonIntShapes)
if intermediates:
shapes.extend(listIntermediates(geo))
# Return Result
return shapes
示例4: getNodesOverload
def getNodesOverload(poseObj, nodes, *args):
# NOTE: poseObj already has an attr 'metaRig' which is filled
# automatically in the main buildInternalPoseData() call
metaNode = poseObj.metaRig
currentSelection = cmds.ls(sl=True, l=True)
filteredNodes = []
if not issubclass(type(metaNode), r9Meta.MetaHIKControlSetNode):
# see if we have a left or right controller selected and switch to the
# appropriate subMetaSystem
if cmds.getAttr('%s.mirrorSide' % currentSelection[0]) == 1:
print '\nFinger : PoseOverload Handler : %s >> side: Left' % metaNode
filteredNodes = metaNode.L_ArmSystem.L_FingerSystem.getChildren()
[filteredNodes.append(node) for node in cmds.listRelatives(filteredNodes, type='joint', ad=True, f=True)]
elif cmds.getAttr('%s.mirrorSide' % currentSelection[0]) == 2:
print '\nFinger : PoseOverload Handler : %s >> side: Right' % metaNode
filteredNodes = metaNode.R_ArmSystem.R_FingerSystem.getChildren()
[filteredNodes.append(node) for node in cmds.listRelatives(filteredNodes, type='joint', ad=True, f=True)]
else:
if currentSelection[0] == metaNode.LeftWristEffector or currentSelection[0] == metaNode.LeftHand:
[filteredNodes.append(node) for node in cmds.listRelatives(metaNode.LeftHand, type='joint', ad=True, f=True)]
elif currentSelection[0] == metaNode.RightWristEffector or currentSelection[0] == metaNode.RightHand:
[filteredNodes.append(node) for node in cmds.listRelatives(metaNode.RightHand, type='joint', ad=True, f=True)]
# modify the actual PoseData object, changing the data to be matched on index
# rather than using the standard name or metaMap matching
poseObj.metaPose = False
poseObj.matchMethod = 'index'
return filteredNodes
示例5: select_node_by_type
def select_node_by_type(nodeType):
sel = cmds.ls(sl=True, l=True)
sel_ad = cmds.listRelatives(sel, ad=True, f=True) + sel
cmds.select(cl=True)
for node in sel_ad:
if cmds.nodeType(node) == nodeType:
cmds.select((cmds.listRelatives(node, p=True)), add=True)
示例6: write_hierarchy
def write_hierarchy(guide):
"""
Simple hierarchy data structure
:param position: Guide node
:type position: Guide, str
:returns: Guide
**Example**:
>>> write_hierarchy("C_spine_0_gde")
"""
try:
guide = guide.joint
except Exception:
guide = str(guide)
if not cmds.objExists(guide):
raise NameError("'%s' is not a guide." % guide)
data = {}
all_guides = cmds.listRelatives(guide, allDescendents=True, type="joint") or []
all_guides.insert(0, guide)
for guide in all_guides:
children = [Guide.validate(c) for c in cmds.listRelatives(guide, children=True, type="joint") or []]
guide = Guide.validate(guide)
data[guide] = children
return data
示例7: performTranferV1
def performTranferV1(self):
getMesh=cmds.ls(sl=1)
if len(getMesh)<2:
print "select a skinned mesh group and an unskinned target mesh group"
return
else:
pass
getMeshController=getMesh[0]
getMeshTarget=getMesh[1]
getChildrenController=cmds.listRelatives(getMeshController, c=1, typ="transform")
if getChildrenController==None:
getChildrenController=([getMeshController])
getChildrenTarget=cmds.listRelatives(getMeshTarget, c=1, typ="transform")
if getChildrenTarget==None:
getChildrenTarget=([getMeshTarget])
result = cmds.promptDialog(
title='find XML',
message="Enter path",
text="C:\Users\\"+str(getFolderName)+"\Documents\maya\projects\default\scenes\\",
button=['Continue','Cancel'],
defaultButton='Continue',
cancelButton='Cancel',
dismissString='Cancel' )
if result == 'Continue':
skinPath=cmds.promptDialog(q=1)
if skinPath:
pass
else:
print "nothing collected"
self.callJointsWin(getChildrenController, getChildrenTarget, skinPath)
示例8: _findRelativesByType
def _findRelativesByType(self, embeddedRoot, resList=['lo', 'md', 'hi', 'apos'], byType='shape', resExcludeList=[]):
shapes = None
searchResList = list(set(resList) - set(resExcludeList))
#print 'searchResList: %s'%searchResList
if embeddedRoot != 'master':
shapes = []
for res in searchResList:
if cmds.objExists('%s|%s'%(embeddedRoot, res)):
resShapes = cmds.listRelatives('%s|%s'%(embeddedRoot, res), ad=True, type=byType, f=True)
if resShapes:
shapes.extend(resShapes)
if not shapes:
shapes = None
else:
embeddedCodes = self._findEmbeddedAssets()
index = embeddedCodes.index('master')
embeddedCodes.pop(index)
if cmds.objExists('|master'):
children = cmds.listRelatives('|master')
if children:
shapes = []
for child in children:
if child not in embeddedCodes:
if child in searchResList:
#print 'child:%s' % child
if cmds.objExists('|master|%s'%child):
childShapes = cmds.listRelatives('|master|%s'%child, ad=True, type=byType, f=True)
if childShapes:
shapes.extend(childShapes)
if not shapes:
shapes = None
return shapes
示例9: BindSkeletons
def BindSkeletons(source, dest, method='connect'):
'''
From 2 given root joints search through each hierarchy for child joints, match
them based on node name, then connect their trans/rots directly, or
parentConstrain them. Again cmds for speed
'''
sourceJoints = cmds.listRelatives(source, ad=True, f=True, type='joint')
destJoints = cmds.listRelatives(dest, ad=True, f=True, type='joint')
if cmds.nodeType(source) == 'joint':
sourceJoints.append(source)
if cmds.nodeType(dest) == 'joint':
destJoints.append(dest)
attrs = ['rotateX', 'rotateY', 'rotateZ', 'translateX', 'translateY', 'translateZ']
for sJnt, dJnt in MatchGivenHierarchys(sourceJoints, destJoints):
if method == 'connect':
for attr in attrs:
try:
cmds.connectAttr('%s.%s' % (sJnt, attr), '%s.%s' % (dJnt, attr), f=True)
except:
pass
elif method == 'constrain':
try:
cmds.parentConstraint(sJnt, dJnt, mo=True)
except:
pass
示例10: extractFaces
def extractFaces( faceList, delete=False ):
'''
extracts the given faces into a separate object - unlike the maya function, this is actually
useful... the given faces are extracted to a separate object, and can be optionally deleted from
the original mesh if desired, or just duplicated out.
'''
newMeshes = []
#get a list of meshes present in the facelist
cDict = componentListToDict( faceList )
for mesh, faces in cDict.iteritems():
#is the mesh a shape or a transform - if its a shape, get its transform
if cmd.nodeType( mesh ) == 'mesh':
mesh = cmd.listRelatives( mesh, pa=True, p=True )[ 0 ]
dupeMesh = cmd.duplicate( mesh, renameChildren=True )[ 0 ]
children = cmd.listRelatives( dupeMesh, pa=True, typ='transform' )
if children: cmd.delete( children )
#now delete all faces except those we want to keep
cmd.select( [ '%s.f[%d]' % (dupeMesh, idx) for idx in range( numFaces( dupeMesh ) ) ] )
cmd.select( [ '%s.f[%d]' % (dupeMesh, idx) for idx in faces ], deselect=True )
cmd.delete()
newMeshes.append( dupeMesh )
if delete:
cmd.delete( faceList )
return newMeshes
示例11: getCamera
def getCamera(self):
_selection = cmds.ls(selection=True)
# check selection length
if len(_selection) == 0:
# check panel for camera if selection is empty
_panel = cmds.getPanel(withFocus=True)
_typeOfPanel = mm.eval("getPanel -typeOf " + _panel)
# check if modelpanel with camera is active
if _typeOfPanel == "modelPanel":
# get camera from modelpanel
_cameraname = cmds.modelPanel(_panel, query=True, camera=True)
_camerashape = cmds.listRelatives(_cameraname, shapes=True)[0]
else:
# no selection, no modelpanel active
_cameraname = "Nul"
_camerashape = "Nul"
else:
# selection is not emtpy
_cameraname = _selection[0]
_camerashape = cmds.listRelatives(_cameraname, shapes=True)[0]
# check if selected shape is camera
if cmds.nodeType(_camerashape) != "camera":
# selection is not camera
_cameraname = "Nul"
_camerashape = "Nul"
self.name = _cameraname
self.shape = _camerashape
示例12: transferUvHierarchy
def transferUvHierarchy( fromTopGroup, toTopGroup):
fromChildren = cmds.listRelatives( fromTopGroup, ad=True, type='mesh', fullPath=True)[1:]
toChildren = cmds.listRelatives( toTopGroup, ad=True, type='mesh', fullPath=True)[1:]
print fromChildren
tmp = copy.copy(fromChildren)
for fChild in tmp:
split = fChild.split("|")[1:]
#print split
split[0] = toTopGroup
tChild = "|" + "|".join( split)
print fChild, tChild
if tChild in toChildren:
fromChildren.remove( fChild)
toChildren.remove( tChild)
cmds.select( fChild, r=True)
tShapes = getShapes(tChild)
print 'transfered \n%s \n | \n%s' % (fChild, tChild)
tChildShapeOrig = tShapes[0]+'Orig'
if (cmds.objectType(fChild) == 'transform' and cmds.objectType(tChild) == 'transform' and cmds.objectType(tChildShapeOrig) == 'mesh'):
cmds.select( tChildShapeOrig, add=True)
cmds.transferAttributes( transferPositions=0, transferNormals=0, transferUVs=2, transferColors=0, sampleSpace=4, sourceUvSpace="map1", targetUvSpace="map1", searchMethod=3, flipUVs=0, colorBorders=1)
print toChildren
print fromChildren
示例13: setImageRes
def setImageRes(self):
""" Sets image width to resolution """
skyDomeLgtList = self.getSkyDomeLgtList()
areaLgtList = self.getAreaLgtList()
print ''
print '-------------------------------------------------'
for lgt in skyDomeLgtList:
lgtName = mc.listRelatives(lgt,p=True)
img = self.imgPath(lgt)
if img == 'None':
print '# '+ lgtName[0] + ' ===> no file image attached'
else:
xres = self.imgInfo(str(img))
mc.setAttr(lgt+'.resolution',int(xres))
print '# ' + lgtName[0] + ' ===> set resolution to [ ' + str(xres) + ' ]'
for lgt in areaLgtList:
lgtName = mc.listRelatives(lgt,p=True)
img = self.imgPath(lgt)
if img == 'None':
print '# '+ lgtName[0] + ' ===> no file image attached'
else:
xres = self.imgInfo(str(img))
mc.setAttr(lgt+'.aiResolution',int(xres))
print '# ' + lgtName[0] + ' ===> set resolution to [ ' + str(xres) + ' ]'
print '-------------------------------------------------'
print ''
示例14: altFrame
def altFrame(*args):
# cmds.nodeType(sel), object type
# optimize, real slow
pnl = cmds.getPanel(withFocus=True)
typ = cmds.getPanel(typeOf=pnl)
if typ == 'modelPanel':
sel = cmds.ls(sl=True, fl=True)
gs = ac.GraphSelection()
locs = []
if sel:
for item in sel:
if cmds.objectType(item, i='transform') or cmds.objectType(item, i='joint'):
loc = cn.locator(obj=item, ro='zxy', X=0.35, constrain=False, shape=False)[0]
locs.append(loc)
else:
try:
print cmds.listRelatives(item, parent=True)[0], '_______________'
loc = cn.locator(obj=cmds.listRelatives(item, parent=True)[0], ro='zxy', X=0.35, constrain=False, shape=False)
print loc, '_____________________'
loc = loc[0]
locs.append(loc)
except:
message('didnt frame object: ' + item)
cmds.select(locs)
mel.eval("fitPanel -selected;")
cmds.delete(locs)
gs.reselect()
else:
message('select an object')
else:
mel.eval("fitPanel -selected;")
示例15: multObjShapeUpdate
def multObjShapeUpdate():
sel_objs = cmds.ls(sl=True,fl=True)
if len(sel_objs)>0:
files_to_import = cmds.fileDialog2(fileFilter = '*.obj', dialogStyle = 2, caption = 'import multiple object files', fileMode = 4,okc="Import")
if len(files_to_import) == len(sel_objs):
object_names = [file_to_import.split('/')[-1].split('.obj')[0] for file_to_import in files_to_import]
if len(sel_objs) == len([x for x in object_names if x in sel_objs]):
for file_to_import in files_to_import:
object_name = file_to_import.split('/')[-1].split('.obj')[0]
returnedNodes = cmds.file('%s' % file_to_import, i = True, type = "OBJ", rnn=True, ignoreVersion = True, options = "mo=0", loadReferenceDepth = "all" )
cmds.delete(cmds.ls(returnedNodes,type="objectSet"))
geo = cmds.listRelatives(cmds.ls(returnedNodes,g=1)[0],p=1)
cmds.rename( geo, "newShape_{0}".format(object_name))
new_shapes = [s for s in cmds.listRelatives(cmds.ls(g=1),p=1) if "newShape_" in s]
cur_shapes = sel_objs
for new in new_shapes:
for cur in cur_shapes:
if new.split("newShape_")[1] == cur:
blendshapeNd = cmds.blendShape(new,cur)[0]
cmds.setAttr("{0}.{1}".format(blendshapeNd,new),1)
cmds.delete(cur_shapes,ch=True)
cmds.delete(new_shapes)
cmds.confirmDialog(m="---===All Shapes Updated!===---")
else:
cmds.confirmDialog(m="--==Not Matching The Name!==--")
else:
cmds.confirmDialog(m="--==Please Select The Same Number Of Objects!==--")
else:
cmds.confirmDialog(m="--==Please Select Something!==--")