I cant seem to query custom attributes/nodes

I am creating objects and attaching a custom attribute to it in OpenMaya:


	nAttr = OpenMaya.MFnNumericAttribute()
	myNewScaler.xyz = nAttr.create( "scaleXYZ", "xyz", OpenMaya.MFnNumericData.kDouble, 20.0 )
	nAttr.setMin(0.0)
	nAttr.setSoftMax(100.0)
	nAttr.setKeyable(True)
	nAttr.setStorable(True)

What I need to be able to do is when I select an object I need to see if this attribute exists so I can apply values to it.

For some reason I cannot query it, When I list all attributes on the object it gives me the basic nodes:

print cmds.listAttr( )
[u'message', u'caching', u'isHistoricallyInteresting', u'nodeState', ....]

So I won’t be able to query it:

cmds.attributeQuery( 'scaleXYZ', node = obj, exists=True )

Do I have to call something like: “nAttr.registerNodeToMaya()”?! I ask because with the class reference I don’t see: .setKeyable() or .setStorable() http://download.autodesk.com/us/maya/2009help/api/class_m_fn_numeric_attribute.html so I don’t know what else I am missing from the docs, so am I even 'Registering" it to the attributes?

How can I get this attribute node?

Worse case I use:

if '%s.%s' % (attribute, node) != None:

But I would rather stay away from that.

Are you actually attaching the attribute to your node? For your example code:

myNewScaler.addAttribute(myNewScaler.xyz)

Yes I am, I just omitted it for the example:


try:
    myNewScaler.addAttribute( myNewScaler.xyz)
except Exception as e:
    print e

Not sure what to tell you. We have a plugin with some custom nodes in it, and the attributes can be queried just fine. All of our code for adding attributes is in a function called “nodeInitializer”. That function is called by the function “registerNode” from the “MFnPlugin” class. (Of course, depending on what type of node you are creating, you may need to use “registerTransform” instead of “registerNode”.)