"Nesting" compound Maya attributes

I’m attempting to create a set of custom attributes on a node within Maya as a means to store configuration data for a tool I’m developing. For one of these custom attributes, I’d like to replicate what one sees with the translateX attribute of the “Transform Attributes” attribute group found ubiquitously on nodes within Maya (i.e., a float3 attribute with visible edit boxes that is a child of a compound attribute).

The following code works as expected (it results in 3 editable number fields being displayed in the Attribute Editor):

cmds.addAttr( longName='sanders', attributeType='double3' )
cmds.addAttr( longName='bess', attributeType='double', parent='sanders' )
cmds.addAttr( longName='les', attributeType='double', parent='sanders' )
cmds.addAttr( longName='wes', attributeType='double', parent='sanders' )

However if I try to nest the above float3 attribute as a child of a compound attribute as follows, problems ensue. I can still get/set the float3’s sub values, but the values themselves (i.e., the edit boxes) are no longer displayed in the Attribute Editor.

cmds.addAttr( longName='sampson', numberOfChildren=1, attributeType='compound' )
cmds.addAttr( longName='sanders', attributeType='double3', parent='sampson' )
cmds.addAttr( longName='bess', attributeType='double', parent='sanders' )
cmds.addAttr( longName='les', attributeType='double', parent='sanders' )
cmds.addAttr( longName='wes', attributeType='double', parent='sanders' )

If possible, I’d prefer to display this information to allow artists to conveniently view and edit these values.

Attributes need to be keyable to show up in the channel box. Try the following:


cmds.addAttr( longName='sampson', numberOfChildren=1, attributeType='compound')
cmds.addAttr( longName='sanders', attributeType='double3', parent='sampson' )
cmds.addAttr( longName='bess', attributeType='double', parent='sanders', keyable = True)
cmds.addAttr( longName='les', attributeType='double', parent='sanders', keyable = True)
cmds.addAttr( longName='wes', attributeType='double', parent='sanders', keyable = True)

Edit:

My bad, I misread. I thought you were looking to put them in the channel box.

Hmm interesting, if i do it as floats, they show up in the attribute editor just fine, but yeah, i’m seeing the same behavior with doubles, that is:


#Attribute Editor friendly
sph, sh = pm.polyCube()

sph.addAttr('root',at='compound',nc=1)
sph.addAttr('childA',at='float3',p='root')
sph.addAttr('childA1',at='float',p='childA')
sph.addAttr('childA2',at='float',p='childA')
sph.addAttr('childA3',at='float',p='childA')

Whereas:


#Attribute editor unfriendly
sph, sh = pm.polyCube()

sph.addAttr('root',at='compound',nc=1)
sph.addAttr('childA',at='double3',p='root')
sph.addAttr('childA1',at='double',p='childA')
sph.addAttr('childA2',at='double',p='childA')
sph.addAttr('childA3',at='double',p='childA')

I even tried it with a few other data types (strings, etc), and those are also Attribute Editor friendly. Tried force setting the readable and writable flags too just for grins, but yeah no dice…Might be worth bouncing off of Autodesk?

Thanks for the assistance. You guys put the awesome in TA.org. :):

Floats do indeed seem to be better behaved than doubles, and for my purposes, floats will do just fine. That said, I’m still running into some odd behavior. The edit boxes are visible (as desired), but I’m noticing that the “display name” of the float3 attribute gets replaced with name of its parent (that is, the compound object) when I deselect and then re-select the node. I say “display name” because I can still get/set the “sub” float attributes using the float3 attribute’s “actual” name. Just for additional clarity I’ve added some images below using the follow code as provided by Seth:

#Attribute Editor friendly
sph, sh = pm.polyCube()

sph.addAttr('root',at='compound',nc=1)
sph.addAttr('childA',at='float3',p='root')
sph.addAttr('childA1',at='float',p='childA')
sph.addAttr('childA2',at='float',p='childA')
sph.addAttr('childA3',at='float',p='childA')

Before “refresh”:

After “refresh”:

Is anyone else seeing this anomaly? I’m running Maya 2012 (64-bit) on Win7 (sp1).