Maya's Add Attribute dialogue allows you to add new attributes to nodes. Everybody knows.
Everybody knows you can make your custom attributes keyable or non-keyable, hidden or visible, you can set their default values, their minimum and maximum accepted inputs, and you can even change their data type.
Everybody knows!
But does everybody know that there are more data types available than the ones that show up in the dialogue options?
No, of course not, why would they? It's not like Maya tells you!
This is one of the biggest reasons to get scripting ASAP. Because Maya offers more functionality than its UI gives you access to.
Suppose you desire a custom attribute that you know will be used to drive the rotation of something. Say a foot roll attribute to drive - after the values have gone through some math nodes - the rotation of a foot's tarsus and toe joints.
Great idea. But say... if you know it's going into a rotation attribute, and you know that rotation attributes are of the datatype angle, it sure would be nice if your custom foot roll attribute was also of type angle, so no unitConversion nodes become necessary.
This is totally doable! But not through the Add Attribute dialogue Maya's native UI provides you with. The only way to add attributes in data types beyond these initial six is via script.
The Maya function we want is addAttr()
So once we've imported the Maya commands class to Python...
import maya.cmds as cmds
... we'll quickly establish some variables. The name of the node to which we're adding the attribute, and the name we want the attribute to have...
node = "footCtrl"
attrName = "footRoll"
... Now let's do this!
cmds.addAttr( node, longName=attrName, attributeType="doubleAngle" defaultValue=0, keyable=True)
Nice.
Well "angle" is how we might talk about it, you and me, but the addAttr() function expects certain arguments corresponding to the different data types that are available. The argument it's expecting if you're wanting the angle data type is "doubleAngle".
No comments:
Post a Comment