本文整理汇总了Python中maya.cmds.addAttr函数的典型用法代码示例。如果您正苦于以下问题:Python addAttr函数的具体用法?Python addAttr怎么用?Python addAttr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了addAttr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_functionality
def _create_functionality(self):
ctl = self.get_control(0)
attrs = ['heel', 'ball', 'tip', 'bankIn', 'bankOut']
for attr in attrs:
cmds.addAttr(ctl.ctl, ln=attr, at="double", min=-10, max=10)
cmds.setAttr("%s.%s" % (ctl.ctl, attr), cb=True)
cmds.setAttr("%s.%s" % (ctl.ctl, attr), k=True)
# Standard connections
self.range_detail = {}
for attr in attrs:
sr = cmds.createNode("setRange", name=name.create_name(self.position, self.description, 0, "%sRange" % attr))
self.range_detail[attr] = sr
# Create settings node connections
for settings_attr in ['minX', 'maxX', 'oldMinX', 'oldMaxX']:
titled_attr = re.sub('([a-zA-Z])', lambda k: k.groups()[0].upper(), settings_attr, 1)
settings_full_attr = "%s.%s%s" % (self.setup_node, attr, titled_attr)
cmds.addAttr(self.setup_node, ln="%s%s" % (attr, titled_attr), at="double")
cmds.setAttr(settings_full_attr, cb=True)
cmds.setAttr(settings_full_attr, k=True)
cmds.connectAttr(settings_full_attr, "%s.%s" % (sr, settings_attr))
# Load settings for part
if self.settings_file:
log.debug("Settings file found! Loading...")
key = os.path.splitext(os.path.basename(self.part_file))[0]
data = SettingsFileHandler(key).read()
for full_attr, value in data.items():
if cmds.objExists(full_attr):
cmds.setAttr(full_attr, value)
else:
log.warning("No settnings file found, please create before continuing.")
示例2: stampCompiled
def stampCompiled(self, audioNodes):
'''
Used by the compiler - stamp the audioNodes from which this audio
track was compiled from
'''
cmds.addAttr(self.audioNode, longName='compiledAudio', dt='string')
cmds.setAttr('%s.compiledAudio' % self.audioNode, ','.join(audioNodes), type="string")
示例3: switch
def switch(node,attr,value=0,inputNames=list(),inputValues=list()):
'''
:param node:
:param attr:
:param value:
:param inputName:
:param inputValues:
:return:
'''
attrName = "{0}.{1}".format(node,attr)
choiceName = "{0}_{1}_switch".format(node,attr)
cmds.createNode("choice",name=choiceName)
cmds.addAttr(node,ln=attr,at="enum",en=":".join(inputNames),dv=value,keyable=True)
for i in range(len(inputValues)):
choiceAttr = "output{0}".format(i)
cmds.addAttr(choiceName,ln=choiceAttr,at="double3")
cmds.addAttr(choiceName,ln="{0}x".format(choiceAttr),at="double",p=choiceAttr,dv=inputValues[i][0])
cmds.addAttr(choiceName,ln="{0}y".format(choiceAttr),at="double",p=choiceAttr,dv=inputValues[i][1])
cmds.addAttr(choiceName,ln="{0}z".format(choiceAttr),at="double",p=choiceAttr,dv=inputValues[i][2])
cmds.connectAttr("{0}.{1}".format(choiceName,choiceAttr),"{0}.input[{1}]".format(choiceName,i))
cmds.connectAttr(attrName,"{0}.selector".format(choiceName),f=True)
return "{0}.output".format(choiceName)
示例4: addRmanPrimVar
def addRmanPrimVar(mesh,attrName,attrType='float',paintable=False):
'''
'''
# Prefix attr
attr = 'rmanF'+attrName
# Data type
if attrType == 'float': dataType = 'doubleArray'
if attrType == 'vector': dataType = 'vectorArray'
if attrType == 'string': dataType = 'stringArray'
# Check mesh
if not glTools.utils.mesh.isMesh(mesh):
raise Exception('Mesh "'+mesh+'" does not exist!!')
# Check attr
if mc.objExists(mesh+'.'+attr):
raise Exception('Attribute "'+mesh+'.'+attr+'" already exists!!')
# Get shape
meshShape = mc.listRelatives(mesh,s=True,ni=True,pa=True)
if not meshShape:
raise Exception('Unable to determine shape for mesh "'+mesh+'"!!')
# Add attribute
mc.addAttr(meshShape[0],ln=attr,dt=dataType)
# Make paintable
if paintable: mc.makePaintable('mesh',attr,attrType=dataType)
示例5: copy_user_attr
def copy_user_attr(selparentshapes, seltargetshapes, copyUV=True):
listattrvalue = {}
listdatatype = {}
userattr = cmds.listAttr(selparentshapes, ud=True)
if copyUV and cmds.nodeType(seltargetshapes) == 'mesh' and cmds.nodeType(selparentshapes) == 'mesh':
cmds.transferAttributes(selparentshapes, seltargetshapes, transferUVs=1, transferColors=2, searchMethod=3, sampleSpace=5, flipUVs=False)
if userattr:
for attr in userattr:
nodetype = cmds.nodeType(selparentshapes)
checkrendershape = cmds.getAttr(selparentshapes + '.intermediateObject')
if checkrendershape != 1 or nodetype != 'mesh':
key = attr
value = cmds.getAttr("%s.%s" % (selparentshapes, key))
data = cmds.getAttr("%s.%s" % (selparentshapes, key), typ=True)
listattrvalue[key] = value
listdatatype[key] = data
checkrendershape = cmds.getAttr(seltargetshapes + '.intermediateObject')
if checkrendershape != 1:
for key in listattrvalue:
if not cmds.attributeQuery(key, node=seltargetshapes, ex=True):
if listdatatype[key] == 'string':
cmds.addAttr(seltargetshapes, longName=key, dataType=listdatatype[key])
cmds.setAttr("%s.%s" % (seltargetshapes, key), listattrvalue[key], type=listdatatype[key])
else:
cmds.addAttr(seltargetshapes, longName=key)
cmds.setAttr("%s.%s" % (seltargetshapes, key), listattrvalue[key])
else:
cmds.warning('Attribute ' + key + ' already on ' + seltargetshapes)
if cmds.getAttr("%s.%s" % (seltargetshapes, key), se=True):
if listdatatype[key] == 'string':
cmds.setAttr("%s.%s" % (seltargetshapes, key), listattrvalue[key], type=listdatatype[key])
else:
cmds.setAttr("%s.%s" % (seltargetshapes, key), listattrvalue[key])
示例6: connect
def connect( self, obj, slot=None ):
'''
performs the actual connection of an object to a connect slot
'''
if not cmd.objExists(obj):
return -1
#if the user is trying to connect the trigger to itself, return zero which is the reserved slot for the trigger
if apiExtensions.cmpNodes( self.obj, obj ):
return 0
if slot is None:
slot = self.nextSlot()
if slot <= 0:
return 0
#make sure the connect isn't already connected - if it is, return the slot number
existingSlots = self.isConnected(obj)
if existingSlots:
return self.getConnectSlots(obj)[0]
conPrefix = 'zooTrig'
prefixSize = len(conPrefix)
slotPath = "%s.%s%d" % (self.obj, conPrefix, slot)
if not objExists( slotPath ):
cmd.addAttr(self.obj,ln= "%s%d" % (conPrefix, slot), at='message')
cmd.connectAttr( "%s.msg" % obj, slotPath, f=True )
self.cacheConnect( slot )
return slot
示例7: add_wf_mat_name_attr
def add_wf_mat_name_attr(*args):
r'''addes a material name attribute of WFMaterialName based on diffuse file connection
'''
mat_pairs=[]
mats = cmds.ls(mat=True)
for mat in mats:
_file = cmds.listConnections('%s.color' % mat)
if _file :
tex_path = cmds.getAttr(_file[0] + '.fileTextureName')
idx = tex_path.lower().find('assets')
if idx != -1:
new_name = '/' + tex_path[idx+7:-6]
attr_list = cmds.listAttr(mat)
if not ('WFMaterialName' in attr_list):
print 'Attribute not in list, making attribute'
cmds.addAttr(mat, dt="string", ln="WFMaterialName")
cmds.setAttr(mat + '.WFMaterialName', new_name, type="string" )
# print ([mat, new_name])
mat_pairs.append([mat, new_name])
else:
print 'Material: \n %s' % mat
print 'String \"assets\" does not exist in the path\n %s' % tex_path
return mat_pairs
示例8: _create_meta_data
def _create_meta_data(self):
"""
Creates a network node to hold the meta data for the rig.
"""
network_node = cmds.createNode("network")
meta_node_name = self._get_unique_name("metaNode", "DyMETA")
meta_node = cmds.rename(network_node, meta_node_name)
data = {
"rootGroup" : self.root_group,
"rigName" : self.rig_name,
"parentControl" : self.parent_control,
"controls" : self.controls,
"pointLock" : self.point_lock,
"startFrame" : self.start_frame,
"endFrame" : self.end_frame,
"dynamicControl" : self.dynamic_control,
"metaNode" : meta_node,
"hairSystem" : self.hair_system}
# build data
for meta, data in data.iteritems():
if meta == "controls":
cmds.addAttr(meta_node, dt="stringArray", ln=meta)
cmds.setAttr("{0}.{1}".format(meta_node, meta),
*([len(data)]+data), type="stringArray")
continue
cmds.addAttr(meta_node, dt="string", ln=meta)
cmds.setAttr("{0}.{1}".format(meta_node, meta),
data, type="string")
示例9: addIdAttr
def addIdAttr(self,*args):
selList = self.listSelected()
meshList = self.getMeshList(selList)
# add attribute to selected meshes
for mesh in meshList:
if not mc.objExists(mesh+'.'+self.idGroupAttr):
mc.addAttr(mesh,ln = self.idGroupAttr,sn = self.idGroupAttr,at = "long",dv = -1)
示例10: createAssetSetFromSelect
def createAssetSetFromSelect(name = 'asset1', type = ''):
asset = mc.sets(name = "%s" % name)
mc.addAttr(asset, longName = 'asset', niceName = "Asset", dataType = 'string')
mc.addAttr(asset, longName = 'type', niceName = "Type", dataType = 'string')
mc.setAttr("%s.asset" % asset, name, type = "string")
mc.setAttr("%s.type" % asset, type, type = "string")
return asset
示例11: addSymEdgeAttr
def addSymEdgeAttr(edge):
'''
Add mesh symmetry edge attribute based on specified mesh edge.
@param edge: Mesh edge that defined the center edge row of a symmetrical mesh
@type edge: str
'''
# Check Edge
edge = mc.filterExpand(edge,ex=True,sm=32) or []
if not edge:
raise Exception('No valid mesh edge selected!')
if len(edge) > 1:
print('Multiple mesh edges found! Using first edge only ("'+edge[0]+'").')
edge = edge[0]
# Get Edge Mesh
mesh = mc.ls(edge,o=True) or []
if not mesh:
raise Exception('Unable to determine mesh from edge!')
if len(mesh) > 1:
print('Multiple mesh objects found from edge!')
mesh = mesh[0]
# Get Edge ID
edgeID = glTools.utils.component.index(edge)
# Add Attribute
symAttr = 'symmetryEdgeId'
if not mc.objExists(mesh+'.'+symAttr):
mc.addAttr(mesh,ln=symAttr,at='long',min=0,dv=edgeID)
mc.setAttr(mesh+'.'+symAttr,edgeID)
# Return Result
return mesh+'.'+symAttr
示例12: rsChName
def rsChName(i_s_textField, s_name):
l_oSels = rsObjList()
i_LockState = cmds.getAttr(l_oSels[2], lock=True)
if i_LockState:
cmds.setAttr(l_oSels[2], lock=False)
if s_name == "NewName":
s_NewName = l_oSels[0] + "." + i_s_textField
cmds.renameAttr(l_oSels[2], i_s_textField)
if i_LockState:
cmds.setAttr(s_NewName, lock=True)
s_search = i_s_textField
else:
cmds.addAttr(l_oSels[2], edit=True, niceName=i_s_textField)
if i_LockState:
cmds.setAttr(l_oSels[2], lock=True)
s_search = l_oSels[1]
l_ChannelAtList = rsChannelAtList()
l_AttrKey = l_ChannelAtList[0]
l_AttrKeyHidden = l_ChannelAtList[1]
if l_AttrKey or l_AttrKeyHidden:
cmds.textScrollList("rsAttributeScroll", edit=True, removeAll=True, append=l_AttrKey)
cmds.textScrollList("rsAttributeScrollHidden", edit=True, removeAll=True, append=l_AttrKeyHidden)
cmds.select(cl=True)
cmds.select(l_oSels[0], r=True)
rsSearchInScroll(s_search)
return True
示例13: rsChangeCheck
def rsChangeCheck(i_b_state, i_s_floatField):
if i_s_floatField == "rsMinField":
i_b_state = cmds.checkBox("rsMinBox", query=True, value=True)
else:
i_b_state = cmds.checkBox("rsMaxBox", query=True, value=True)
l_oSels = rsObjList()
if i_b_state == True:
if i_s_floatField == "rsMinField":
b_minimum = cmds.attributeQuery(l_oSels[1], node=l_oSels[0], minExists=True)
f_atValue = 0.0
if b_minimum == 1:
f_atValue = (cmds.attributeQuery(l_oSels[1], node=l_oSels[0], minimum=True))[0]
else:
cmds.addAttr(l_oSels[2], edit=True, hasMinValue=True)
if i_s_floatField == "rsMaxField":
b_maximum = cmds.attributeQuery(l_oSels[1], node=l_oSels[0], maxExists=True)
f_atValue = 1.0
if b_maximum == 1:
f_atValue = (cmds.attributeQuery(l_oSels[1], node=l_oSels[0], maximum=True))[0]
else:
cmds.addAttr(l_oSels[2], edit=True, hasMaxValue=True)
cmds.addAttr(l_oSels[2], edit=True, maxValue=f_atValue)
cmds.floatField(i_s_floatField, edit=True, value=f_atValue, enable=True)
else:
cmds.floatField(i_s_floatField, edit=True, value=0, enable=False)
if i_s_floatField == "rsMinField":
cmds.addAttr(l_oSels[2], edit=True, hasMinValue=False)
else:
cmds.addAttr(l_oSels[2], edit=True, hasMaxValue=False)
return True
示例14: createGuide
def createGuide(self, *args):
Base.StartClass.createGuide(self)
# Custom GUIDE:
cmds.addAttr(self.moduleGrp, longName="flip", attributeType='bool')
cmds.setAttr(self.moduleGrp+".flip", 0)
cmds.addAttr(self.moduleGrp, longName="indirectSkin", attributeType='bool')
cmds.setAttr(self.moduleGrp+".indirectSkin", 0)
cmds.setAttr(self.moduleGrp+".moduleNamespace", self.moduleGrp[:self.moduleGrp.rfind(":")], type='string')
self.cvJointLoc, shapeSizeCH = ctrls.cvJointLoc(ctrlName=self.guideName+"_JointLoc1", r=0.3)
self.connectShapeSize(shapeSizeCH)
self.jGuide1 = cmds.joint(name=self.guideName+"_JGuide1", radius=0.001)
cmds.setAttr(self.jGuide1+".template", 1)
cmds.parent(self.jGuide1, self.moduleGrp, relative=True)
self.cvEndJoint, shapeSizeCH = ctrls.cvLocator(ctrlName=self.guideName+"_JointEnd", r=0.1)
self.connectShapeSize(shapeSizeCH)
cmds.parent(self.cvEndJoint, self.cvJointLoc)
cmds.setAttr(self.cvEndJoint+".tz", 1.3)
self.jGuideEnd = cmds.joint(name=self.guideName+"_JGuideEnd", radius=0.001)
cmds.setAttr(self.jGuideEnd+".template", 1)
cmds.transformLimits(self.cvEndJoint, tz=(0.01, 1), etz=(True, False))
ctrls.setLockHide([self.cvEndJoint], ['tx', 'ty', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz'])
cmds.parent(self.cvJointLoc, self.moduleGrp)
cmds.parent(self.jGuideEnd, self.jGuide1)
cmds.parentConstraint(self.cvJointLoc, self.jGuide1, maintainOffset=False, name=self.jGuide1+"_ParentConstraint")
cmds.parentConstraint(self.cvEndJoint, self.jGuideEnd, maintainOffset=False, name=self.jGuideEnd+"_ParentConstraint")
cmds.scaleConstraint(self.cvJointLoc, self.jGuide1, maintainOffset=False, name=self.jGuide1+"_ScaleConstraint")
cmds.scaleConstraint(self.cvEndJoint, self.jGuideEnd, maintainOffset=False, name=self.jGuideEnd+"_ScaleConstraint")
示例15: add
def add(self,objectList):
'''
Adds the channel state attr to all specified objects
@param objectList: List of objects to add flags to
@type objectList: list
'''
# Add Channel State Attrs
for obj in objectList:
# Check obj
if not mc.objExists(obj):
raise Exception('Object "'+obj+'" does not exist!')
if not glTools.utils.transform.isTransform(obj):
raise Exception('Object "'+obj+'" is not a valid transform!')
if mc.objExists(obj+'.channelState'):
print ('Object "'+obj+'" already has a "channelState" attribute! Skipping...')
# Add channelState attr
#mc.addAttr(obj,ln='channelState',at='enum',en=':Keyable:NonKeyable:Locked:',m=1,dv=-1)
mc.addAttr(obj,ln='channelState',at='enum',en=':Keyable:NonKeyable:Locked:',m=1)
# Set channelState flag values
for i in range(len(self.channel)):
if mc.getAttr(obj+'.'+self.channel[i],l=1):
# Set Locked State
mc.setAttr(obj+'.channelState['+str(i)+']',2)
elif not mc.getAttr(obj+'.'+self.channel[i],k=1):
# Set NonKeyable State
mc.setAttr(obj+'.channelState['+str(i)+']',1)
else:
# Set Keyable State
mc.setAttr(obj+'.channelState['+str(i)+']',0)
# Alias Attribute
mc.aliasAttr(self.channel[i]+'_state',obj+'.channelState['+str(i)+']')