.NET MDGMessage

Hello, all!

I have previously posted over at Autodesk Area, but alas, no result. Please assist!

I’m having trouble using MDGMessage’s addNodeAdded/RemovedCallback in the .NET API. I’ve successfully used it in previous plugins in both C++ and Python, but it seems to be implemented in the .NET API in such a confusing way, and I can’t wrap my head around it. I’ve hunted through the .NET DLL (openmayacs.dll/xml) and found that it has the functionality there, but the events are missing and replaced with some class I can’t quite figure out how to use.

Has anybody successfully added these events using the .NET API before, and if you have, could you share how it was done?

If I happen to get it working through more fiddling, I’ll post my solution here.

Thanks!

You’re probably hitting this:

Events instead of function pointers – The C# event pattern replaces the message registration mechanism of the MMessage derived classes (for example, MSceneMessage, MNodeMessage, and so forth). Therefore, you can register or unregister your callbacks by simply adding or removing them to/from the corresponding event handler of the MMessage derived class.
For instance, do MDagMessage.ParentAddedEvent += callback instead of MDagMessage::addParentAddedCallback(callback).
For the MSceneMessage class, each message identified by a value of the enum Message now has an independent event handler; therefore, the enum is no longer meaningful. For instance, do MSceneMessage.SceneUpdate += callback instead of MSceneMessage::addCallback( MSceneMessage::kSceneUpdate, callback ).
For callbacks related to an instance of an object (MDagPath, MPlug, and so forth), the event handler can be found directly in the class of that object. For instance, do obj.NodeAddedToModel += callback (with obj of type MObject) instead of MModelMessage::addNodeAddedToModelCallback(obj, callback).
To avoid memory leaks, you must deregister your callbacks (by removing them from the corresponding event handler) when the callbacks are no longer needed. A new mechanism has been added to automatically deregister the callbacks when the plug-in is unloaded from Maya.
To see how events are used, refer to the pluginCallbacks example in the <…>\devkit\dotnet\examples folder. For more information on C# events see C# events in MSDN.

Hmm, I see.

I do see that most of the events exposed are done so through the standard EventHandler<____FunctionArgs>, but both the node added and removed are done so through some cryptic Maya MEventArgsIndex<MNodeFunctionArgs, string> class. Interestingly, the Maya class variables for the node added and removed callbacks are both both static (whereas the other actual C# events are not). My main issue is that there’s no C# event exposed for me to do the good ol’ += on to add my function to, but I may be missing something obvious. :D:

As a shot in the dark, it may be worth me trying to put the NodeAddedToModel callback on the root node to see if that somewhat mirrors my desired effect, but I’m not certain that would work.

Apologies for raising the dead, but this has been acknowledged by Autodesk as a bug in their .NET API: http://forums.autodesk.com/t5/maya-programming/net-mdgmessage/m-p/6231404
At the time of writing, I contacted Autodesk Support, and they still have no “official word” on the bugfix.

[QUOTE=KasumiL5x;30016]Apologies for raising the dead, but this has been acknowledged by Autodesk as a bug in their .NET API: http://forums.autodesk.com/t5/maya-programming/net-mdgmessage/m-p/6231404
At the time of writing, I contacted Autodesk Support, and they still have no “official word” on the bugfix.[/QUOTE]

So how did you manage to check if a node was created or removed?

I ended up switching to the C++ API. Autodesk replied to my thread saying that it’s logged to be fixed, but as far as I’m aware, it’s still not fixed even in the latest 2017 release.