Trouble Scripting Custom Attribute

This script does create a custom attribute in the node editor, but doesn’t show
up in the channel box ???

import maya.cmds as cmds
cmds.file(new = True, f = True)
sphere_xform, sphere_shape = cmds.polySphere( n = ‘Earth’)
cmds.addAttr(
sphere_xform,
attributeType = ‘float’,
shortName = ‘mass’,
longName = ‘mass’,
defaultValue = 5.9742e24)

try setting keyable = True,

The thing to remember is that the channel box is a convenient interface for animation. Any attribute that is not keyable will not show up in the channel box.

You just need to add keyable=True to your call to cmds.addAttr(). If you don’t, then it won’t appear in the channel box, but you can still find it in the attribute editor under the “extra attributes” dropdown.


The keyable keyword specifically determines whether the attribute should appear in the channel box or not. Also FYI, that is all that it does. It does not actually make the attribute un-keyable, it just means that it won’t be keyed when you press the ‘s’ key to key all. You can still right-click it in the attribute editor under “extra attributes” and set a key that way.

There is a hidden keyword to cmds.addAttr, but it is basically useless. You can’t actually prevent an attribute from having keys set unless you lock it (locked=True).

This is a little bit annoying because of the way this stuff is named