本文整理匯總了Python中maya.cmds.addAttr方法的典型用法代碼示例。如果您正苦於以下問題:Python cmds.addAttr方法的具體用法?Python cmds.addAttr怎麽用?Python cmds.addAttr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類maya.cmds
的用法示例。
在下文中一共展示了cmds.addAttr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: lock
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def lock():
"""Lock scene
Add an invisible node to your Maya scene with the name of the
current file, indicating that this file is "locked" and cannot
be modified any further.
"""
if not cmds.objExists("lock"):
with lib.maintained_selection():
cmds.createNode("objectSet", name="lock")
cmds.addAttr("lock", ln="basename", dataType="string")
# Permanently hide from outliner
cmds.setAttr("lock.verticesOnlySet", True)
fname = cmds.file(query=True, sceneName=True)
basename = os.path.basename(fname)
cmds.setAttr("lock.basename", basename, type="string")
示例2: getBaseCtrl
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def getBaseCtrl(self, sCtrlType, sAttrName, sCtrlName, fRadius, iDegree = 1, iSection = 8):
nCtrl = None
self.ctrlCreated = False
try:
nCtrl= self.masterGrp.getAttr(sAttrName)
except pymel.MayaAttributeError:
try:
nCtrl = pymel.PyNode(self.prefix + sCtrlName)
except pymel.MayaNodeError:
if (sCtrlName != (self.prefix + "Option_Ctrl")):
nCtrl = pymel.PyNode(self.ctrls.cvControl(sCtrlType, sCtrlName, r=fRadius, d=iDegree, dir="+X"))
else:
nCtrl = pymel.PyNode(self.ctrls.cvCharacter(sCtrlType, sCtrlName, r=(fRadius*0.2)))
self.ctrlCreated = True
finally:
#Since there is no connection between the master and the node found, create the connection
self.masterGrp.addAttr(sAttrName, attributeType='message')
nCtrl.message.connect(self.masterGrp.attr(sAttrName))
return nCtrl
示例3: createEyelidJoints
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def createEyelidJoints(self, side, lid, middle, cvEyelidLoc, jointLabelNumber, *args):
''' Create the eyelid joints to be used in the needed setup.
Returns EyelidBaseJxt and EyelidJnt created for rotate and skinning.
'''
# declating a concatenated name used for base to compose:
baseName = side+self.userGuideName+"_"+self.langDic[self.langName][lid]+"_"+self.langDic[self.langName]['c042_eyelid']+middle
# creating joints:
eyelidBaseZeroJxt = cmds.joint(name=baseName+"_Base_Zero_Jxt", rotationOrder="yzx", scaleCompensate=False)
eyelidBaseJxt = cmds.joint(name=baseName+"_Base_Jxt", rotationOrder="yzx", scaleCompensate=False)
eyelidZeroJxt = cmds.joint(name=baseName+"_Zero_Jxt", rotationOrder="yzx", scaleCompensate=False)
eyelidJnt = cmds.joint(name=baseName+"_Jnt", rotationOrder="yzx", scaleCompensate=False)
cmds.addAttr(eyelidJnt, longName='dpAR_joint', attributeType='float', keyable=False)
utils.setJointLabel(eyelidJnt, jointLabelNumber, 18, self.userGuideName+"_"+self.langDic[self.langName][lid]+"_"+self.langDic[self.langName]['c042_eyelid']+middle)
cmds.select(eyelidZeroJxt)
eyelidSupportJxt = cmds.joint(name=baseName+"_Jxt", rotationOrder="yzx", scaleCompensate=False)
cmds.setAttr(eyelidSupportJxt+".translateX", self.ctrlRadius*0.1)
# positioning and orienting correctely eyelid joints:
cmds.delete(cmds.aimConstraint(cvEyelidLoc, eyelidBaseZeroJxt, aimVector=(0,0,1), worldUpType="objectrotation", worldUpObject=self.eyelidJxt))
cmds.delete(cmds.parentConstraint(cvEyelidLoc, eyelidZeroJxt, mo=False))
cmds.setAttr(eyelidZeroJxt+".rotateX", 0)
cmds.setAttr(eyelidZeroJxt+".rotateY", 0)
cmds.setAttr(eyelidZeroJxt+".rotateZ", 0)
cmds.select(self.eyelidJxt)
return eyelidBaseJxt, eyelidJnt
示例4: cvLocator
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def cvLocator(self, ctrlName, r=1, d=1, guide=False, *args):
"""Create and return a cvLocator curve to be usually used in the guideSystem and the clusterHandle to shapeSize.
"""
curveInstance = self.getControlInstance("Locator")
curve = curveInstance.cvMain(False, "Locator", ctrlName, r, d, '+Y', (0, 0, 0), 1, guide)
if guide:
# create an attribute to be used as guide by module:
cmds.addAttr(curve, longName="nJoint", attributeType='long')
cmds.setAttr(curve+".nJoint", 1)
# colorize curveShape:
self.colorShape([curve], 'blue')
# shapeSize setup:
shapeSizeCluster = self.shapeSizeSetup(curve)
return [curve, shapeSizeCluster]
return curve
#@utils.profiler
示例5: from_value
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def from_value(cls, value, base_name):
"""
Generating a scalar vector from a value
This function generates a node and a channel used to host the value
and attach the channel to a NScalar vector class
Args:
:value: float,int, the value of the NScalar
:base_name: str, the name we will use for the node + "_vec", the attribute name will
be generated with base_name + "_from_value"
"""
node = cmds.createNode("transform", n= base_name + '_vec')
attr_name = base_name + "_from_value"
cmds.addAttr(node, ln = attr_name, at="float",
k=1)
cmds.setAttr(node + '.' + attr_name, value)
return cls(node + '.' + attr_name , base_name)
示例6: _createResolutionComboBox
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def _createResolutionComboBox(self):
userProps = cross3d.UserProps(self._nativePointer)
# Local models have a resolution metadata.
# Maybe it's not a good idea.
if resolutionAttr in userProps:
del userProps[resolutionAttr]
resolutions = ':'.join(userProps.get('resolutions', []))
# Object should support referencing, but referencing hasn't been setup, so create the structure.
cmds.addAttr(self._nativeName(), longName=resolutionAttr, attributeType="enum", enumName=resolutions)
# Make the attribute viewable, but not keyable in the channelBox
try:
cmds.setAttr(self._attrName(), keyable=False, channelBox=True)
# Consume a runtime error if the resolution attribute was in the reference. This is only a
# issue with some of our first models, Asset Exporter will remove them from future exports.
except RuntimeError as error:
pattern = r"setAttr: The attribute '[^']+' is from a referenced file, thus the keyable state cannot be changed."
if not re.match(pattern, error.message):
raise
示例7: msgConnect
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def msgConnect(attribFrom, attribTo, debug=0):
# TODO needs a mode to dump all current connections (overwrite/force)
objFrom, attFrom = attribFrom.split('.')
objTo, attTo = attribTo.split('.')
if debug: print 'msgConnect>>> Locals:', locals()
if not attrExists(attribFrom):
cmds.addAttr(objFrom, longName=attFrom, attributeType='message')
if not attrExists(attribTo):
cmds.addAttr(objTo, longName=attTo, attributeType='message')
# check that both atts, if existing are msg atts
for a in (attribTo, attribFrom):
if cmds.getAttr(a, type=1) != 'message':
cmds.warning('msgConnect: Attr, ' + a + ' is not a message attribute. CONNECTION ABORTED.')
return False
try:
return cmds.connectAttr(attribFrom, attribTo, f=True)
except Exception as e:
print e
return False
示例8: convertSkelSettingsToNN
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def convertSkelSettingsToNN(delete=1):
orig = 'SkeletonSettings_Cache'
if cmds.objExists(orig):
if cmds.nodeType(orig) == 'unknown':
new = cmds.createNode('network')
for att in cmds.listAttr(orig):
if not cmds.attributeQuery(att, node=new, exists=1):
typ = cmds.attributeQuery(att, node=orig, at=1)
if typ == 'typed':
cmds.addAttr(new, longName=att, dt='string')
if cmds.getAttr(orig + '.' + att):
cmds.setAttr(new + '.' + att, cmds.getAttr(orig + '.' + att), type='string')
elif typ == 'enum':
cmds.addAttr(new, longName=att, at='enum', enumName=cmds.attributeQuery(att, node=orig, listEnum=1)[0])
cmds.delete(orig)
cmds.rename(new, 'SkeletonSettings_Cache')
示例9: __create_config_control
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def __create_config_control(self, parent):
self.config_control = cmds.createNode(
"transform", name="{}_config_ctrl".format(self.name)
)
if parent:
cmds.parent(self.config_control, parent)
common.opm_parent_constraint(self.end_joint, self.config_control)
common.lock_and_hide(self.config_control, "trsv")
cmds.addAttr(
self.config_control,
ln="ikFk",
minValue=0.0,
maxValue=1.0,
defaultValue=0.0,
keyable=True,
)
示例10: addControlInfo
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def addControlInfo(self, cvNode, className=True, size=True, degree=True, direction=True, rot=True, dpGuide=False, *args):
""" Add some information in the curve transform node of the control.
"""
cmds.addAttr(cvNode, longName="dpControl", attributeType='bool')
cmds.setAttr(cvNode+".dpControl", 1)
if dpGuide:
cmds.addAttr(cvNode, longName="dpGuide", attributeType='bool')
cmds.setAttr(cvNode+".dpGuide", 1)
cmds.addAttr(cvNode, longName="version", dataType='string')
cmds.setAttr(cvNode+".version", self.dpUIinst.dpARVersion, type="string")
if self.cvID:
cmds.addAttr(cvNode, longName="controlID", dataType='string')
cmds.setAttr(cvNode+".controlID", self.cvID, type="string")
if className:
cmds.addAttr(cvNode, longName="className", dataType='string')
cmds.setAttr(cvNode+".className", self.guideModuleName, type="string")
if size:
cmds.addAttr(cvNode, longName="size", attributeType='float')
cmds.setAttr(cvNode+".size", self.cvSize)
if degree:
cmds.addAttr(cvNode, longName="degree", attributeType='short')
cmds.setAttr(cvNode+".degree", self.cvDegree)
if direction:
cmds.addAttr(cvNode, longName="direction", dataType='string')
cmds.setAttr(cvNode+".direction", self.cvDirection, type="string")
if rot:
cmds.addAttr(cvNode, longName="cvRotX", attributeType='double')
cmds.addAttr(cvNode, longName="cvRotY", attributeType='double')
cmds.addAttr(cvNode, longName="cvRotZ", attributeType='double')
cmds.setAttr(cvNode+".cvRotX", self.cvRot[0])
cmds.setAttr(cvNode+".cvRotY", self.cvRot[1])
cmds.setAttr(cvNode+".cvRotZ", self.cvRot[2])
示例11: getBaseGrp
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def getBaseGrp(self, sAttrName, sGrpName):
nGrpNode = None
try:
nGrpNode = self.masterGrp.getAttr(sAttrName)
except pymel.MayaAttributeError:
try:
nGrpNode = pymel.PyNode(sGrpName)
except pymel.MayaNodeError:
nGrpNode = pymel.createNode("transform", name=sGrpName)
finally:
#Since there is no connection between the master and the node found, create the connection
self.masterGrp.addAttr(sAttrName, attributeType='message')
nGrpNode.message.connect(self.masterGrp.attr(sAttrName))
return nGrpNode
示例12: dpCreateRemapNode
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def dpCreateRemapNode(self, fromNode, fromAttr, toNodeBaseName, toNode, toAttr, number, sizeFactor, oMin=0, oMax=1, iMin=0, iMax=1, *args):
""" Creates the nodes to remap values and connect it to final output (toNode) item.
"""
fromNodeName = utils.extractSuffix(fromNode)
remap = cmds.createNode("remapValue", name=fromNodeName+"_"+fromAttr+"_"+str(number).zfill(2)+"_"+toAttr.upper()+"_RmV")
outMaxAttr = toNodeBaseName+"_"+str(number).zfill(2)+"_"+toAttr.upper()
if "t" in toAttr:
if not cmds.objExists(fromNode+".sizeFactor"):
cmds.addAttr(fromNode, longName="sizeFactor", attributeType="float", defaultValue=sizeFactor, keyable=False)
cmds.addAttr(fromNode, longName=outMaxAttr, attributeType="float", defaultValue=oMax, keyable=False)
md = cmds.createNode("multiplyDivide", name=fromNodeName+"_"+fromAttr+"_"+str(number).zfill(2)+"_"+toAttr.upper()+"_SizeFactor_MD")
cmds.connectAttr(fromNode+"."+outMaxAttr, md+".input1X", force=True)
cmds.connectAttr(fromNode+".sizeFactor", md+".input2X", force=True)
cmds.connectAttr(md+".outputX", remap+".outputMax", force=True)
else:
cmds.addAttr(fromNode, longName=outMaxAttr, attributeType="float", defaultValue=oMax, keyable=False)
cmds.connectAttr(fromNode+"."+outMaxAttr, remap+".outputMax", force=True)
cmds.setAttr(remap+".inputMin", iMin)
cmds.setAttr(remap+".inputMax", iMax)
cmds.setAttr(remap+".outputMin", oMin)
cmds.connectAttr(fromNode+"."+fromAttr, remap+".inputValue", force=True)
# check if there's an input connection and create a plusMinusAverage if we don't have one to connect in:
connectedList = cmds.listConnections(toNode+"."+toAttr, destination=False, source=True, plugs=False)
if connectedList:
if cmds.objectType(connectedList[0]) == "plusMinusAverage":
inputList = cmds.listConnections(connectedList[0]+".input1D", destination=False, source=True, plugs=False)
cmds.connectAttr(remap+".outValue", connectedList[0]+".input1D["+str(len(inputList))+"]", force=True)
else:
if cmds.objectType(connectedList[0]) == "unitConversion":
connectedAttr = cmds.listConnections(connectedList[0]+".input", destination=False, source=True, plugs=True)[0]
else:
connectedAttr = cmds.listConnections(toNode+"."+toAttr, destination=False, source=True, plugs=True)[0]
pma = cmds.createNode("plusMinusAverage", name=toNode+"_"+toAttr.upper()+"_PMA")
cmds.connectAttr(connectedAttr, pma+".input1D[0]", force=True)
cmds.connectAttr(remap+".outValue", pma+".input1D[1]", force=True)
cmds.connectAttr(pma+".output1D", toNode+"."+toAttr, force=True)
if cmds.objectType(connectedList[0]) == "unitConversion":
cmds.delete(connectedList[0])
else:
cmds.connectAttr(remap+".outValue", toNode+"."+toAttr, force=True)
示例13: createGuide
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
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="fatherB", dataType='string')
cmds.setAttr(self.moduleGrp+".moduleNamespace", self.moduleGrp[:self.moduleGrp.rfind(":")], type='string')
self.cvALoc, shapeSizeCH = self.ctrls.cvJointLoc(ctrlName=self.guideName+"_JointLocA", r=0.3, d=1, guide=True)
self.connectShapeSize(shapeSizeCH)
self.jAGuide = cmds.joint(name=self.guideName+"_jAGuide", radius=0.001)
cmds.setAttr(self.jAGuide+".template", 1)
cmds.parent(self.jAGuide, self.moduleGrp, relative=True)
self.cvBLoc, shapeSizeCH = self.ctrls.cvJointLoc(ctrlName=self.guideName+"_JointLocB", r=0.3, d=1, guide=True)
self.connectShapeSize(shapeSizeCH)
cmds.parent(self.cvBLoc, self.cvALoc)
cmds.setAttr(self.cvBLoc+".tz", 3)
cmds.setAttr(self.cvBLoc+".rotateX", 180)
self.jBGuide = cmds.joint(name=self.guideName+"_jBGuide", radius=0.001)
cmds.setAttr(self.jBGuide+".template", 1)
cmds.transformLimits(self.cvBLoc, tz=(0.01, 1), etz=(True, False))
self.ctrls.setLockHide([self.cvBLoc], ['tx', 'ty', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz'])
cmds.parent(self.cvALoc, self.moduleGrp)
cmds.parent(self.jBGuide, self.jAGuide)
cmds.parentConstraint(self.cvALoc, self.jAGuide, maintainOffset=False, name=self.jAGuide+"_ParentConstraint")
cmds.parentConstraint(self.cvBLoc, self.jBGuide, maintainOffset=False, name=self.jBGuide+"_ParentConstraint")
cmds.scaleConstraint(self.cvALoc, self.jAGuide, maintainOffset=False, name=self.jAGuide+"_ScaleConstraint")
cmds.scaleConstraint(self.cvBLoc, self.jBGuide, maintainOffset=False, name=self.jBGuide+"_ScaleConstraint")
示例14: createGuide
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
def createGuide(self, *args):
Base.StartClass.createGuide(self)
# Custom GUIDE:
cmds.addAttr(self.moduleGrp, longName="nJoints", attributeType='long')
cmds.setAttr(self.moduleGrp+".nJoints", 1)
cmds.addAttr(self.moduleGrp, longName="flip", attributeType='bool')
cmds.setAttr(self.moduleGrp+".flip", 0)
cmds.setAttr(self.moduleGrp+".moduleNamespace", self.moduleGrp[:self.moduleGrp.rfind(":")], type='string')
self.cvJointLoc, shapeSizeCH = self.ctrls.cvJointLoc(ctrlName=self.guideName+"_JointLoc1", r=0.3, d=1, guide=True)
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 = self.ctrls.cvLocator(ctrlName=self.guideName+"_JointEnd", r=0.1, d=1, guide=True)
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))
self.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")
示例15: createGuide
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import addAttr [as 別名]
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.addAttr(self.moduleGrp, longName='holder', attributeType='bool')
cmds.setAttr(self.moduleGrp+".holder", 0)
cmds.setAttr(self.moduleGrp+".moduleNamespace", self.moduleGrp[:self.moduleGrp.rfind(":")], type='string')
self.cvJointLoc, shapeSizeCH = self.ctrls.cvJointLoc(ctrlName=self.guideName+"_JointLoc1", r=0.3, d=1, guide=True)
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 = self.ctrls.cvLocator(ctrlName=self.guideName+"_JointEnd", r=0.1, d=1, guide=True)
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))
self.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")