本文整理汇总了Python中maya.cmds.listAttr函数的典型用法代码示例。如果您正苦于以下问题:Python listAttr函数的具体用法?Python listAttr怎么用?Python listAttr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了listAttr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setMirrorObject
def setMirrorObject( fromList, toList ):
for i in range( len( fromList ) ):
fromCtl = fromList[i]
toCtl = toList[i]
isTransMirror = False
isZRotMirror = False
for transMirrorName in CtlInfo.xTransMirrorTargetNames:
if fromCtl.find( transMirrorName ) != -1:
isTransMirror = True
for zRotMirror in CtlInfo.zRotMirrorTargetNames:
if fromCtl.find( zRotMirror ) != -1 and fromCtl.find( 'wing_big4_CTL' ) == -1:
isZRotMirror = True
try:
if isTransMirror:
trValue = cmds.getAttr( fromCtl + '.t' )[0]
cmds.setAttr( toCtl+'.t', -trValue[0], trValue[1], trValue[2] )
elif isZRotMirror:
rotValue = cmds.getAttr( fromCtl + '.r' )[0]
cmds.setAttr( toCtl + '.r', -rotValue[0], -rotValue[1], rotValue[2] )
else:
keys = cmds.listAttr( fromCtl, k=1 )
for key in keys:
value = cmds.getAttr( fromCtl+'.'+key )
cmds.setAttr( toCtl + '.' + key, value )
except: pass
listAttr = cmds.listAttr( fromCtl, ud=1, k=1 )
if not listAttr: continue
for attr in listAttr:
cmds.setAttr( toCtl+'.'+attr, cmds.getAttr( fromCtl+'.'+attr ) )
示例2: setAttributeState
def setAttributeState(lock=None, hide=None):
sel = mc.ls(sl=True)
if not sel:
OpenMaya.MGlobal.displayWarning('Please make a selection.')
return
channels = utl.getSelectedChannels()
doAll = not bool(channels)
kwargs = dict()
for obj in sel:
attrs = channels[:]
#we unhide first, so hidden attributes can get unlocked.
if hide is False and doAll:
attrs = ['tx','ty','tz','rx','ry','rz','sx','sy','sz','v']
ud = mc.listAttr(obj, userDefined=True)
if ud:
attrs+=ud
elif doAll:
attrs = mc.listAttr(obj, keyable=True)
if lock is not None:
kwargs['lock'] = lock
if hide is not None:
kwargs['keyable'] = not hide
if attrs:
for attr in attrs:
try:
mc.setAttr(obj+'.'+attr, **kwargs)
except StandardError: pass
示例3: getAttribute
def getAttribute(self):
# if lattice point is selected, returning list is 'attr.attr'
keyable = cmds.listAttr(self.name, k=True, s=True)
if keyable:
for attr in keyable:
if attr not in self.attributesDriven:
# hacky -- if attr.attr format, remove first attr
hack = False
if '.' in attr:
attr = attr.split('.')[1]
hack = True
try:
a = Attribute(self.name, attr, poseOnly=self.poseOnly)
a.get()
self.attributes.append(a)
except:
message('Hack fail: ' + attr)
else:
a = Attribute(self.name, attr, poseOnly=self.poseOnly)
a.get()
self.attributes.append(a)
settable = cmds.listAttr(self.name, cb=True) # future fix, make part of one pass, current code copied from above
if settable:
for attr in settable:
if attr not in self.attributesDriven:
# hacky -- if attr.attr format, remove first attr
if '.' in attr:
attr = attr.split('.')[1]
a = Attribute(self.name, attr, poseOnly=self.poseOnly, settable=True)
a.get()
self.attributes.append(a)
示例4: channelBox_Filter_Items
def channelBox_Filter_Items(box):
with sysCmd.Undo(0):
filters = []
names = []
for f in box.filter_items:
if f == "attr_userDefined":
user_cb = cmds.listAttr(ud=1, cb=1)
user_kv = cmds.listAttr(ud=1, k=1, v=1)
if user_cb:
names += user_cb
if user_kv:
names += user_kv
elif f == "attr_translate":
names.append("translateX")
names.append("translateY")
names.append("translateZ")
elif f == "attr_rotate":
names.append("rotateX")
names.append("rotateY")
names.append("rotateZ")
elif f == "attr_scale":
names.append("scaleX")
names.append("scaleY")
names.append("scaleZ")
else:
filters.append(f.split("_")[-1])
if len(filters) == 0 and len(names) == 0:
cmds.channelBox(box.channelbox, e=1, update=1)
return
_f = [] # create the actual filters
if "animCurve" in filters:
_f.append(cmds.itemFilterAttr(hasCurve=1))
if "expression" in filters:
_f.append(cmds.itemFilterAttr(hasExpression=1))
if "drivenKey" in filters:
_f.append(cmds.itemFilterAttr(hasDrivenKey=1))
if "scaleRotateTranslate" in filters:
_f.append(cmds.itemFilterAttr(scaleRotateTranslate=1))
if names:
_f.append(cmds.itemFilterAttr(byNameString=names))
destination = _f[0]
odd = len(_f) % 2 # determines odd/even number
loops = len(_f) / 2 + (1 if odd else 0)
for i in range(loops): # create union filters
index_1 = i * 2
index_2 = i * 2 + 1
use_last = odd and i + 1 == loops
destination = cmds.itemFilterAttr(union=(_f[index_1], _f[index_2] if not use_last else destination))
box.filter = destination
cmds.itemFilterAttr(box.filter, e=1, negate=box.saved_states["invertShown"][0])
cmds.channelBox(box.channelbox, e=1, attrFilter=box.filter, update=1)
for f in _f:
cmds.delete(f)
示例5: setMirrorObjectOnce
def setMirrorObjectOnce( target ):
otherTarget = ''
if target in CtlInfo.leftCtls:
otherTarget = target.replace( 'L_', 'R_' )
elif target in CtlInfo.rightCtls:
otherTarget = target.replace( 'R_', 'L_' )
if not otherTarget: return None
isTransMirror = False
isZRotMirror = False
for transMirrorName in CtlInfo.xTransMirrorTargetNames:
if target.find( transMirrorName ) != -1:
isTransMirror = True
for zRotMirror in CtlInfo.zRotMirrorTargetNames:
if target.find( zRotMirror ) != -1 and target.find( 'wing_big4_CTL' ) == -1:
isZRotMirror = True
if isTransMirror:
trValue = cmds.getAttr( target + '.t' )[0]
cmds.setAttr( otherTarget+'.t', -trValue[0], trValue[1], trValue[2] )
elif isZRotMirror:
rotValue = cmds.getAttr( target + '.r' )[0]
cmds.setAttr( otherTarget + '.r', -rotValue[0], -rotValue[1], rotValue[2] )
else:
keys = cmds.listAttr( target, k=1 )
for key in keys:
value = cmds.getAttr( target+'.'+key )
cmds.setAttr( otherTarget + '.' + key, value )
listAttr = cmds.listAttr( target, ud=1, k=1 )
if not listAttr: return None
for attr in listAttr:
cmds.setAttr( otherTarget+'.'+attr, cmds.getAttr( target+'.'+attr ) )
示例6: utilChannelBoxAttributes
def utilChannelBoxAttributes(source):
attributes = cmds.listAttr(source, k=True)
#extend non-keyable in channel box
nonKeyable = cmds.listAttr(source, cb=True)
if nonKeyable:
attributes.extend(nonKeyable)
return attributes
示例7: updateInputOutputs
def updateInputOutputs(self):
"""
finds attributes on module with "input_" & "output_" prefix then populates dicts
"""
# Get input attrs
inputsAttrs = cmds.listAttr( self.container, st='input_*')
# Get output attrs
outputsAttrs = cmds.listAttr( self.container, st='output_*')
if inputsAttrs:
for attr in inputsAttrs:
# get attr key
key = Util.getSuffix(attr)
if key != "data":
# get connected obj
objs = Util.getConnectedObjects( (self.container + "." + attr) )
# store obj
self.inputs[key] = Util.getFirst(objs)
if outputsAttrs:
for attr in outputsAttrs:
# get attr key
key = Util.getSuffix(attr)
if key != "data":
# get connected obj
objs = Util.getConnectedObjects( (self.container + "." + attr) )
# store obj
self.outputs[key] = Util.getFirst(objs)
示例8: importAssetCache
def importAssetCache(self, cacheXmlLt, cacheErrorCheck = False):
""" cacheXmlLt = "R:/data/cache/sq001/sh001/light/char/ben00c_ben/ben00c_ben.xml" """
if os.path.exists(cacheXmlLt):
cacheChannels = mc.cacheFile(fileName=cacheXmlLt,q=1,channelName=1)
cacheGeos = self.getCacheGeos()
cacheGeoDict, cacheChannelsTmp = {}, []
for chn in cacheChannels:
for geo in cacheGeos:
baseChn = utils.stripNames(utils.convertName(chn, "texture"))
baseGeo = utils.stripNames(utils.stripNames(geo, ":"), "|")
if baseChn in baseGeo:
cacheGeoDict[chn] = geo
cacheChannelsTmp.append(chn)
continue
else:
utils.msgWin("Error", "File does not exist : %s"%cacheXmlLt, self.silent)
return False
if cacheErrorCheck:
missedChannels = list(set(cacheChannels).difference(set(cacheGeoDict.keys())))
if len(missedChannels) > 0:
msg = "Cache geometry missing\n"
msg += "\n".join(missedChannels)
utils.msgWin("Error", msg, self.silent)
return missedChannels
else:
return False
for chNode in self.getCacheNodes():
mc.delete(chNode)
for chn in cacheGeoDict.keys():
deformShp = cacheGeoDict[chn]
try:
shpSwitch = mc.deformer(deformShp, type="historySwitch")
except:
continue
shpHist = mc.listHistory(deformShp, pdo=1)
if shpHist:
for hist in shpHist:
if mc.nodeType(hist) == "tweak":
dblList = mc.listAttr("%s.plist"%hist, m= 1)
fltList = mc.listAttr("%s.vlist"%hist, m= 1)
dbCon, flCon = False, False
if dblList:
if len(dblList) > 1: dbCon = True
if fltList:
if len(fltList) > 1: flCon = True
if not(dbCon or flCon):
mc.delete(hist)
break
conns = mc.listConnections("%s.ip[0].ig"%shpSwitch[0], p=1)
mc.connectAttr(conns[0], "%s.ug[0]"%shpSwitch[0])
mc.setAttr("%s.playFromCache"%shpSwitch[0], 1)
mc.getAttr("%s.op[0]"%shpSwitch[0], sl = 1)
mc.setAttr("%s.playFromCache"%shpSwitch[0], 0)
mc.disconnectAttr(conns[0], "%s.ug[0]"%shpSwitch[0])
switch = mc.rename(shpSwitch[0],'cacheSwitch#')
mc.setAttr(switch+'.ihi',0)
cacheNode = mc.cacheFile(f = cacheXmlLt, attachFile = True, ia = '%s.inp[0]'%switch, cnm = chn)
mc.connectAttr(cacheNode+".inRange", switch + '.playFromCache')
utils.msgWin("Message", "Cache loaded successfully for %s"%self.namespace, self.silent)
return True
示例9: attrReset
def attrReset( ):
'''
This function will reset the attributes on the selected objects in the scene.
'''
selected = cmds.ls(sl=True)
# selCB = cmds.channelBox( "mainChannelBox", q=True, sma=True)
for sel in selected:
# Gathering all the attributes from the object.
selCB = cmds.listAttr(sel, k=True)
# Duplicating list because removing from the list your are looping through causes problems.
newAttrs = selCB[:]
try:
[selCB.remove(x) for x in newAttrs if x in cmds.listAttr( selected , k=True, l=True )]
except TypeError:
print( "None of the attributes are locked.")
for attr in selCB:
attrName = "%s.%s" %(sel,attr)
print(attrName)
# Check to see if keyable
if( cmds.getAttr( attrName, k=True) ):
# Get default value
# cmds.attributeQuery( "sx", node="nurbsCircle1", listDefault=True )
attrDV = cmds.attributeQuery( attr, node=sel, listDefault=True)[0]
print( "Object: %s Setting to Default: %s" %(attrName, attrDV))
cmds.setAttr( attrName, attrDV )
示例10: getattributes
def getattributes(self):
for key, nodes in self.oldNodes.iteritems():
if key == 'expression':
expression = True
else:
expression = False
for oldNode in nodes:
listAttr = cmds.listAttr(oldNode)
if listAttr:
self.attributes[nodes[oldNode]] = {}
for attr in listAttr:
try:
self.attributes[nodes[oldNode]].update({attr: {'value': cmds.getAttr(oldNode + '.' + attr)}})
self.attributes[nodes[oldNode]][attr].update({'type': cmds.getAttr(oldNode + '.' + attr, type=True)})
if expression and attr == 'expression':
self.expressions.update({nodes[oldNode]: self.attributes[nodes[oldNode]][attr]['value']})
except RuntimeError as e:
pass
except ValueError as e:
pass
listAttrCustom = cmds.listAttr(oldNode, userDefined=True)
if listAttrCustom:
self.newAttributes[nodes[oldNode]] = {}
for attr in listAttrCustom:
try:
self.newAttributes[nodes[oldNode]].update({attr: {'type': cmds.getAttr(oldNode + '.' + attr, type=True)}})
if cmds.attributeQuery(attr, node=oldNode, minExists=True):
self.newAttributes[nodes[oldNode]][attr].update({'min': cmds.attributeQuery(attr, node=oldNode, min=True)})
if cmds.attributeQuery(attr, node=oldNode, maxExists=True):
self.newAttributes[nodes[oldNode]][attr].update({'max': cmds.attributeQuery(attr, node=oldNode, max=True)})
except RuntimeError as e:
pass
except ValueError as e:
pass
示例11: copyAttribute
def copyAttribute( firstAttr, second ):
first, attr = firstAttr.split( '.' )
keyAttrs = cmds.listAttr( firstAttr, k=1 )
cbAttrs = cmds.listAttr( firstAttr, k=1 )
if not cmds.attributeQuery( attr, node=second, ex=1 ):
attrType = cmds.attributeQuery( attr, node=first, at=1 )
if attrType == 'enum':
enumList = cmds.attributeQuery( attr, node=first, le=1 )
cmds.addAttr( second, ln=attr, at=attrType, en= ':'.join( enumList ) + ':' )
else:
minValue = None
maxValue = None
if cmds.attributeQuery( attr, node=first, mne=1 ):
minValue = cmds.attributeQuery( attr, node=first, min=1 )[0]
if cmds.attributeQuery( attr, node=first, mxe=1 ):
maxValue = cmds.attributeQuery( attr, node=first, max=1 )[0]
if minValue != None and maxValue == None:
cmds.addAttr( second, ln=attr, at=attrType, min=minValue )
elif minValue == None and maxValue != None :
cmds.addAttr( second, ln=attr, at=attrType, max=maxValue )
elif minValue != None and maxValue != None :
cmds.addAttr( second, ln=attr, at=attrType, min=minValue, max=maxValue )
else:
cmds.addAttr( second, ln=attr, at=attrType )
if attr in keyAttrs:
cmds.setAttr( second+'.'+attr, e=1, k=1 )
elif attr in cbAttrs:
cmds.setAttr( second+'.'+attr, e=1, cb=1 )
示例12: userAttrCheck
def userAttrCheck(objList=[], includeShapes=False):
"""
Return a list of user defined attributes for a specified list of nodes (and shapes).
@param objList: List of objects to check for user defined attributes.
@type objList: list
@param includeShapes: Also check shapes for user defined attributes.
@type includeShapes: bool
"""
# Initialize Return List
result = []
# Check objList
if not objList: objList = cmds.ls()
# For each node
for obj in objList:
userAttrs = cmds.listAttr(obj, ud=True)
if not userAttrs: userAttrs = []
for attr in userAttrs:
result.append(obj + '.' + attr)
# Check Shapes
if includeShapes:
shapes = cmds.listRelatives(obj, s=True)
if not shapes: shapes = []
for shape in shapes:
userAttrs = cmds.listAttr(shape, ud=True)
if not userAttrs: userAttrs = []
for attr in userAttrs:
result.append(shape + '.' + attr)
# Return Result
return result
示例13: writeCtrlAttr
def writeCtrlAttr( ctrls = [] , fn = '' ) :
fid = open( fn , 'w' )
ctrlDct = {}
for ctrl in ctrls :
currCtrl = pc.Dag( ctrl )
currShape = pc.Dag( currCtrl.shape )
for each in ( currCtrl , currShape ) :
if mc.objExists( each ) :
attrs = mc.listAttr( each , ud=True )
keyableAttrs = mc.listAttr( each , k=True )
lockAttrs = mc.listAttr( each , l=True )
if attrs :
for attr in attrs :
currCtrlAttr = '%s.%s' % ( each , attr )
ctrlDct[ currCtrlAttr ] = [ False , False ]
if lockAttrs and ( attr in lockAttrs ) :
ctrlDct[ currCtrlAttr ][0] = True
if keyableAttrs and ( attr in keyableAttrs ) :
ctrlDct[ currCtrlAttr ][1] = True
pickle.dump( ctrlDct , fid )
fid.close()
示例14: listNodeConnections
def listNodeConnections(*args,**keywords):
s=True
d=True
sn=False
sel=[]
if len(args)==0:
sel=mc.ls(sl=True)
for a in args:
if isIterable(a):
sel.extend(a)
else:
sel.append(a)
for k in keywords:
if k=='s' or k=='source':
s=keywords[k]
if k=='d' or k=='destination':
d=keywords[k]
if k=='sn' or k=='shortName':
sn=keywords[k]
elif k in locals():
exec(k+'=keywords[k]')
connections=[]
for conn in removeDuplicates(mc.listConnections(sel[0],s=s,d=d,p=True)):
if len(sel)==1 or mc.ls(conn,o=True)[0]==sel[1]:
if mc.connectionInfo(conn,isSource=True):
for dfs in mc.connectionInfo(conn,dfs=True):
if mc.ls(dfs,o=True)[0]==sel[0]:
if sn:
connections.append\
(
[
mc.ls(conn,o=True)[0]+'.'+mc.listAttr(conn,sn=True)[0],
mc.ls(dfs,o=True)[0]+'.'+mc.listAttr(dfs,sn=True)[0]
]
)
else:
connections.append([conn,dfs])
if mc.connectionInfo(conn,id=True):
sfd=mc.connectionInfo(conn,sfd=True)
if mc.ls(sfd,o=True)[0]==sel[0]:
if sn:
connections.append\
(
[
mc.ls(sfd,o=True)[0]+'.'+mc.listAttr(sfd,sn=True)[0],
mc.ls(conn,o=True)[0]+'.'+mc.listAttr(conn,sn=True)[0]
]
)
else:
connections.append([sfd,conn])
return removeDuplicates(connections)
示例15: addObjectID
def addObjectID():
'''
add object id to selected objects. check for existing object ID and add new one if there are existing.
'''
nodeList = cmds.ls(selection = True, dag=True, lf=True, type = 'mesh') # find shape nodes of current selection
allNodes = cmds.ls(type = 'mesh') # look for meshes only in the scene
existingIDs = [0]
for node in allNodes: # go through and check for existing object IDs here
attrList = cmds.listAttr(node)
if 'vrayObjectID' in attrList:
existingIDs.append (cmds.getAttr ('%s.vrayObjectID' % node))
newObjectID = 1
existingIDs.sort() # this is just for cleanliness. not required.
for id in range(max(existingIDs)+2): # look through the list and let's find an unused number if that exists we need to go one beyond the current values so we can add it if needed
if id not in existingIDs:
newObjectID = id
existingIDs.append(newObjectID)
break
for node in nodeList:
attrList = cmds.listAttr(node)
if 'vrayObjectID' not in attrList:
print newObjectID
mel.eval ('vray addAttributesFromGroup %s vray_objectID 1' % node)
cmds.setAttr('%s.vrayObjectID' % node ,newObjectID)
renderElements = cmds.ls (type = 'VRayRenderElement')
addedID = False # clear the slate here
attrsToSearch = ['vray_redid_multimatte','vray_greenid_multimatte','vray_blueid_multimatte'] # just looking for these attrs
multiMatteElements = [] # nice and tidy here
for element in renderElements: #go through and find multi matte elements and add them to our list
if cmds.getAttr('%s.vrayClassType' % element) == 'MultiMatteElement':
multiMatteElements.append(element)
if len(multiMatteElements) < int(math.modf((newObjectID+2)/3)[1]) : # check amount of multi matte elements against how many we can fit in a render element
newMMate = mel.eval('vrayAddRenderElement MultiMatteElement') # add the element
cmds.setAttr('%s.vray_considerforaa_multimatte' % newMMate, 1) #make sure it has AA on it...
multiMatteElements.append(newMMate)
for element in multiMatteElements: # go through the multimatte list
for multimatte in attrsToSearch: # we are looking only through the id attributes
if cmds.getAttr('%s.%s' % (element, multimatte)) == newObjectID : # if we find the ID already just try to skip the rest of the testing
addedID = True
if cmds.getAttr('%s.%s' % (element, multimatte)) == 0 and addedID == False : # didn't find anything eh? good. we add the id to the multimatte.
cmds.setAttr('%s.%s' % (element, multimatte), newObjectID)
addedID = True