Ok, I figured it out:

I don't know what about the MEL approach (I didn't like it anyway).
But as for the 2 other approaches, the problem was the way I instantiated 
MNodeClass.
I thought I was giving it a NoteTypeID, but I was actually trying to 
instantiate is with an MFnTypeID which doesn't work...
I found that out by trying to get it's TypeName afer instanciating it, and 
the AttributeCound, and I got invalid results...
Until I tried to just pass it a NoteTypeName, like "transform" (all 
lower-case), and suddenly it started working.
Eventually, I used "dagNode" (with this exact casing), so I could add the 
extension-attribute to all DAG-nodes.
It also works with my custom MPxData-type, just as well as with the 
StringData.
I didn't end-up having to wrap it in MFnPluginData for this to work - I 
just pass MyMPx::id to the attribute-creation function, and it works.
So, this is how it looks when it works:

MFnTypedAttribute fnAttr;
MObject attr = fnAttr.create(L, S, MyMPx::id); // or: MObject attr = 
fnAttr.create(L, S, MyMPx::id, MObject::kNullObj, &status); 
MNodeClass mnDagNodeClass("dagNode");
status = mnDagNodeClass.addExtensionAttribute(attr);

Realistically, I actually did have to use MFnPluginData in order to 
pre-generate a default-value for my attribute:

MFnPluginData fnData;
MObject defaultValue = fnData.create(MyMPx::id, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);

MFnTypedAttribute fnAttr;
MObject attr = fnAttr.create(L, S, MyMPx::id, defaultValue, &status);
MNodeClass mnDagNodeClass("dagNode");
status = mnDagNodeClass.addExtensionAttribute(attr);

I haven't tried to use the MDGModifier approach, but I would guess it would 
work out just as well, with a proper MNodeClass instance..

I wish there was an easier way to find-out, when trying to instantiate 
MNodeClass, when it doesn't actually work...
I also wish there was a list somewhere of node-names and type-ids...

Anyway, anyone reading this, who wants to write a plugin with this 
use-case, now you know how.

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/93d9261e-42f0-4a52-8110-2b524b7754eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to