本文整理汇总了Python中maya.cmds.listConnections函数的典型用法代码示例。如果您正苦于以下问题:Python listConnections函数的具体用法?Python listConnections怎么用?Python listConnections使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了listConnections函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getKeyAttrConnectedChildren
def getKeyAttrConnectedChildren( topObj ):
children = cmds.listRelatives( topObj, c=1, ad=1, f=1 )
children.append( topObj )
targetChildren = []
targetCons = []
for child in children:
if not cmds.nodeType( child ) in ['joint', 'transform']: continue
listAttrs = cmds.listAttr( child, k=1 )
for attr in listAttrs:
cons = cmds.listConnections( child+'.'+ attr, s=1, d=0 )
if cons:
targetChildren.append( child )
targetCons += cons
else:
parentAttrs = cmds.attributeQuery( attr, node=child, listParent = 1 )
if parentAttrs:
cons= cmds.listConnections( child+'.'+parentAttrs[0], s=1, d=0 )
if cons:
targetChildren.append( child )
targetCons += cons
targetChildren = list( set( targetChildren ) )
targetCons = list( set( targetCons ) )
return targetChildren, targetCons
示例2: removeLayTex
def removeLayTex(self, argsv):
# get shapes of selection:
args = cmds.ls(sl=1)
shapesInSel = cmds.ls(dag=1,o=1,s=1,sl=1)
shapeIndex = 0
for arg in args :
# get shading groups from shapes:
shadingGrps = cmds.listConnections(shapesInSel[shapeIndex],type='shadingEngine')
# get the shaders:
shaders = cmds.ls(cmds.listConnections(shadingGrps),materials=1)
shader = shaders[0]
#print cmds.listRelatives (p=True, arg)
layeredTex = cmds.listConnections(shader, type='layeredTexture')
layeredTex = layeredTex[0]
if (not layeredTex == None):
fileTex = cmds.listConnections(layeredTex, type='file')
fileTex = fileTex[0]
if (not fileTex == None):
cmds.delete(layeredTex)
print 'Connecting ' + shader + '.color to ' + fileTex + '.outColor'
cmds.connectAttr(fileTex+'.outColor', shader+'.color', f=1)
else:
print ('Object ' + arg + ' does not have a file texture attached, skipping')
else:
print ('Object ' + arg + ' does not have a layered texture attached, skipping')
shapeIndex += 1
示例3: getSkinClusterNode
def getSkinClusterNode(obj):
shapes = []
objSets = []
connections = []
skinClusters = []
shapes = cmds.listRelatives(obj, shapes=True)
if shapes and len(shapes) > 0: #found shape node
directSkinClusters = cmds.listConnections(shapes[0], type='skinCluster')
if directSkinClusters:
print '1'
skinClusters.append(directSkinClusters[0])
else:
print '2'
objSets = cmds.listConnections(shapes[0], type='objectSet')
if objSets and len(objSets) > 0: #found objectSet node
print objSets
for objSet in objSets:
connections = cmds.listConnections(objSet, type='skinCluster')
if connections and len(connections) > 0: #found skinCluster node
print '4'
if not connections[0] in skinClusters:
skinClusters.append(connections[0])
if len(skinClusters) > 1:
print "more than one skinClusters found"
else:
return skinClusters[0]
示例4: makeActive
def makeActive( rfn ):
"""
Make active all nested references.
"""
result = []
references = referenceRelatives( rfn, onlyLoaded=False, parents=False )
if references:
m_count = len( references )
if m_count > 1:
for i in range( 0, m_count ):
if references[i] not in result:
result.append( references[i] )
pm = cmds.listConnections( "%s.proxyMsg" % references[i], type="proxyManager" )
if pm:
pm = pm[0]
#Get active reference.
rfn = ""
proxy = cmds.listConnections( "%s.proxyList" % pm, type="reference", source=False, destination=True )
if proxy:
for n in range( 0, len( proxy )):
if cmds.referenceQuery( proxy[n], isLoaded=True ):
rfn = proxy[n]
break
if rfn == "":
rfn = proxy[0]
#Deactivate all non active references.
active = cmds.listConnections( "%s.activeProxy" % pm, plugs=True )
if active:
for n in range( 0, len( active )):
cmds.disconnectAttr( "%s.activeProxy" % pm, active[n] )
#Make active reference.
lproxy = cmds.connectionInfo( "%s.proxyMsg" % rfn, sourceFromDestination=True )
if lproxy:
cmds.connectAttr( "%s.activeProxy" % pm, lproxy )
return result
示例5: memberList
def memberList(layer, objectList=True):
"""
Return a list of objects assigned to the specified layer
@param obj: The layer to return an object list for
@type obj: bool
"""
# Check Layer
if not isLayer(layer):
raise Excpetion('Object "' + layer + '" is not a valid layer type!')
# Get Member List
members = []
if isDisplayLayer(layer):
members = cmds.listConnections(layer + '.drawInfo', s=False, d=True, sh=True)
if isRenderLayer(layer):
members = cmds.listConnections(layer + '.renderInfo', s=False, d=True, sh=True)
if isAnimLayer(layer):
members = cmds.listConnections(layer + '.dagSetMembers', s=True, d=False, sh=True)
# Get List of Objects from Member List
if objectList: members = cmds.ls(members, o=True)
# Format Result
if not members: members = []
members = list(set(members))
# Return Result
return members
示例6: get_shader
def get_shader(node):
'''Get the shader applied to a transform or mesh
:param node: Transform or mesh shape
'''
node_type = cmds.nodeType(node)
if node_type == 'transform':
shape = get_shape(node)
if not shape:
return
elif node_type == 'mesh':
shape = node
try:
shading_engine = cmds.listConnections(shape, type='shadingEngine')[0]
except IndexError:
raise Exception('{} is not attached to a shading engine'.format(shape))
try:
shader = cmds.listConnections(shading_engine + '.surfaceShader')[0]
except IndexError:
raise Exception('{} shadingEngine has no surfaceShader attached'.format(shading_engine))
return shader
示例7: switchProxy
def switchProxy( rfn, to="" ):
if cmds.nodeType( rfn ) == "reference":
pm = cmds.listConnections( rfn, type="proxyManager" )
else:
print "%s has not any connected proxy references." % rfn
return None
if pm:
pm = pm[0]
if to == "":
references = cmds.listConnections( "%s.proxyList" % pm, type="reference", source=False, destination=True )
active = cmds.listConnections( "%s.activeProxy" % pm, source=False, destination=True, plugs=True )
if active:
for i in range( 0, len( references )):
connections = cmds.listConnections( "%s.proxyMsg" % references[i], type="proxyManager", source=True, destination=False, plugs=True )
if connections and active[0] in connections:
return loadReference( references[i-1] )
break
else:
return loadReference( references[0] )
else:
if cmds.objExists( to ) and cmds.nodeType( to ) == "reference":
tm = cmds.listConnections( to, type="proxyManager" )
if tm and pm == tm[0]:
return loadReference( to )
else:
print "%s is not proxy reference for current reference." % to
return None
else:
print "%s is not proxy reference." % to
return None
示例8: createMaterialSelect
def createMaterialSelect():
selNodes = cmds.ls(selection=True) # get selection
mtlSelectToCreate = [] # clean out array
for node in selNodes:
if cmds.nodeType(node) == 'VRayBlendMtl': #make sure it's a vray blend mat
mat = (cmds.listConnections('%s.base_material' % (node))[0])
print mat, node
if mat != None and mat not in mtlSelectToCreate:
mtlSelectToCreate.append(mat)
for n in range(0,9):
mat = (cmds.listConnections('%s.coat_material_%d' % (node,n))) # go thru each coat and add if it's there
if mat != None and mat not in mtlSelectToCreate:
mtlSelectToCreate.append(mat[0])
if cmds.nodeType(node) == 'VRayMtl':
if node not in mtlSelectToCreate:
mtlSelectToCreate.append(node)
for curMat in mtlSelectToCreate:
matSelName = 'mtl_%s' % (curMat) # create a reasonable name
if not cmds.objExists(matSelName): # make sure it doesn't already exist
renderElement = mel.eval('vrayAddRenderElement MaterialSelectElement;') # create render element
renderElement = cmds.rename(renderElement,matSelName) # rename the old to new
cmds.connectAttr (curMat + '.outColor', renderElement + '.vray_mtl_mtlselect') # connect up the shader to the render element
cmds.setAttr (renderElement + '.vray_explicit_name_mtlselect', matSelName, type = 'string') # make sure the name that gets shoved in the exr is named the same
示例9: ConstraintVisibility
def ConstraintVisibility(self, Objects , ControlObject , SpaceSwitchName = 'spaceSwitch', reverse = False ):
if (self.AddNumericParameter (ControlObject, Name = SpaceSwitchName)):
SWMultDiv = cmds.shadingNode("multiplyDivide",asUtility = True ,name = SpaceSwitchName + "SWMultDivide" )
SWMultDiv = self.NameConv.RMRenameBasedOnBaseName(ControlObject, SWMultDiv, NewName = SWMultDiv)
cmds.connectAttr(ControlObject+"."+SpaceSwitchName ,SWMultDiv+".input1X")
cmds.setAttr(SWMultDiv+".input2X",10)
cmds.setAttr(SWMultDiv+".operation",2)
else:
SWMultDiv = cmds.listConnections(ControlObject + "." + SpaceSwitchName, type = "multiplyDivide")[0]
if reverse == True:
ConnectionsList = cmds.listConnections (SWMultDiv + ".outputX", type = "reverse")
reverseSW = ""
if ConnectionsList and len(ConnectionsList) >= 1:
reverseSW = ConnectionsList[0]
else :
reverseSW = cmds.shadingNode('reverse', asUtility=True, name = SpaceSwitchName + "SWReverse")
reverseSW = self.NameConv.RMRenameBasedOnBaseName(ControlObject, reverseSW, NewName ="SWReverse")
cmds.connectAttr( SWMultDiv + ".outputX", reverseSW + ".inputX")
if self.NameConv.RMIsNameInFormat (ControlObject):
reverseSW = self.NameConv.RMRenameBasedOnBaseName(ControlObject,reverseSW, NewName = reverseSW)
else:
reverseSW = self.NameConv.RMRenameNameInFormat(reverseSW)
for eachObject in Objects:
cmds.connectAttr(reverseSW + ".outputX", eachObject + ".visibility")
else:
for eachObject in Objects:
cmds.connectAttr(SWMultDiv + ".outputX", eachObject + ".visibility")
示例10: getWristAngleNode
def getWristAngleNode( target, targetBase=None ):
wristAngleCons = cmds.listConnections( target+'.m', s=0, d=1, type='wristAngle' )
wristAngleNode = ''
if not wristAngleCons:
mmCons = cmds.listConnections( target+'.wm', s=0, d=1, type='multMatrix' )
if mmCons:
wristAngleCons = cmds.listConnections( mmCons[0]+'.o', s=0, d=1, type='wristAngle' )
if wristAngleCons: wristAngleNode = wristAngleCons[0]
else:
wristAngleNode = wristAngleCons[0]
if wristAngleNode: return wristAngleNode
wa = cmds.createNode( 'wristAngle' )
if not targetBase:
targetBase = cmds.listRelatives( target, p=1, f=1 )[0]
cmds.connectAttr( target+'.m', wa+'.inputMatrix' )
else:
mm = cmds.createNode( 'multMatrix' )
cmds.connectAttr( target+'.wm', mm+'.i[0]' )
cmds.connectAttr( targetBase+'.wim', mm+'.i[1]' )
cmds.connectAttr( mm+'.o', wa+'.inputMatrix' )
cmds.select( wa )
return wa
示例11:
def setupStrechy ():
# >>> get IK from selection, get start/end joints & IK curve, determine strechy joints
_IK = cmds.ls (selection = True)[0]
_IKcurve = cmds.listConnections (_IK + '.inCurve', destination = True)[0]
_startJoint = cmds.listConnections (_IK + '.startJoint', destination = True)[0]
_endEffector = cmds.listConnections (_IK + '.endEffector', destination = True)[0]
_endJoint = cmds.listConnections (_endEffector + '.translateX', destination = True)[0]
cmds.select (_endJoint, hierarchy = True)
_jointsTrash = cmds.ls (selection = True)
cmds.select (_startJoint, hierarchy = True)
_strachyJoints_ = cmds.ls (selection = True)
_strachyJoints_ = _strachyJoints_[:len (_strachyJoints_) - len (_jointsTrash)-1]
# >>> setup utility nodes
_curveInfo = cmds.arclen (_IKcurve, constructionHistory = True)
_condtition = cmds.createNode ('condition')
_startLength = cmds.getAttr (_curveInfo + '.arcLength')
_currentLength = cmds.createNode ('multiplyDivide')
cmds.setAttr (_currentLength + '.operation', 2)
cmds.setAttr (_currentLength + '.input2X', _startLength)
cmds.setAttr (_condtition + '.firstTerm', _startLength)
cmds.setAttr (_condtition + '.operation', 4)
cmds.connectAttr (_curveInfo + '.arcLength', _currentLength + '.input1X', force = True)
cmds.connectAttr (_curveInfo + '.arcLength', _condtition + '.secondTerm', force = True)
cmds.connectAttr (_currentLength + '.outputX', _condtition + '.colorIfTrueR', force = True)
# >>> connect calculated scale to joints
for _j in _strachyJoints_:
cmds.connectAttr (_condtition + '.outColorR', _j + '.scaleX', force = True)
示例12: separateMeshsBySkinWeight2
def separateMeshsBySkinWeight2( meshObjs ):
import sgBFunction_connection
import sgBFunction_dag
meshObjs = sgBFunction_dag.getChildrenMeshExists( meshObjs )
meshs = []
for meshObj in meshObjs:
meshs += separateMeshBySkinWeight2( meshObj )
jntAndBindTargets = {}
appendedJnts = []
for sel in meshs:
mmdc = cmds.listConnections( sel, s=1, d=0 )[0]
bindObj = cmds.listConnections( mmdc, s=1, d=0 )[0]
bindObjP = cmds.listRelatives( bindObj, p=1, f=1 )[0]
if not bindObjP in appendedJnts:
appendedJnts.append( bindObjP )
jntAndBindTargets.update( {bindObjP:[]} )
jntAndBindTargets[ bindObjP ].append( sel )
for jnt, bindObjs in jntAndBindTargets.items():
if len( bindObjs ) == 1: continue
bindObj, polyUnite = cmds.polyUnite( bindObjs, n=bindObjs[0] )
bindObj = cmds.rename( bindObj, jnt.split( '|' )[-1]+'_mesh' )
sgBFunction_connection.bindConnect( bindObj, jnt )
示例13: deleteExpression
def deleteExpression(con='', attr=''):
'''
#
'''
# find exp
cnn = cmds.listConnections(con + '.' + attr, s=True, d=False)
if cnn:
if cmds.nodeType(cnn[0]) == 'unitConversion':
cnn_uc = cmds.listConnections(cnn, s=True, d=False, type='expression')
if cnn_uc:
if cmds.nodeType(cnn_uc[0]) == 'expression':
exp = cnn_uc[0]
elif cmds.nodeType(cnn[0]) == 'expression':
exp = cnn[0]
# delete exp
if exp:
st1 = cmds.expression(exp, q=True, s=True)
st2 = 'frame'
if st2 in st1:
cmds.delete(exp)
print 'deleted___ ', con, ' ___ ', exp
else:
print ' nope '
else:
print 'no expression ', attr
示例14: chimaPullThemDown
def chimaPullThemDown() :
num = -6975.209
nodes = mc.ls( sl=True )
tys = []
for node in nodes :
src = mc.listConnections( '%s.ty' % node , p=True , s=True , d=False )[0]
srcType = mc.nodeType( src )
ty = ''
if srcType == 'character' :
ty = mc.listConnections( src , s=True , d=False )[0]
elif srcType == 'animCurveTL' :
ty = src.split( '.' )[0]
else :
print '%s has been constrained to object' % node
ty = None
if ty :
tys.append( ty )
mc.keyframe( tys ,
e=True ,
includeUpperBound=False ,
animation='objects' ,
time=(0,100000) ,
r=True ,
o='move' ,
timeChange=0 ,
valueChange=num
)
示例15: getMuscle
def getMuscle(muscleObject):
"""
Get muscle connected to the specified muscleObject
@param muscleObject: Muscle object to query
@type muscleObject: str
"""
# Get muscle object type
muscleObjType = getMuscleObjectType(muscleObject)
# Get muscle
muscle = ''
if muscleObjType == 'geo':
muscle = muscleObject
elif (muscleObjType == 'profile') or (muscleObjType == 'attachment') or (muscleObjType == 'spline'):
muscleConn = cmds.listConnections(muscleObject + '.muscle', s=True, d=False)
if not muscleConn:
raise Exception('Unable to determine muscle connection from muscleObject "' + muscleObject + '"!')
muscle = muscleConn[0]
elif (muscleObjType == 'attachmentTangent'):
muscleObjParent = cmds.listRelatives(muscleObject, p=True)[0]
muscleConn = cmds.listConnections(muscleObjParent + '.muscle', s=True, d=False)
if not muscleConn:
raise Exception('Unable to determine muscle connection from muscleObject "' + muscleObject + '"!')
muscle = muscleConn[0]
else:
raise Exception('Invalid muscleObjectType value: "' + muscleObjType + '"!')
# Return result
return muscle