Results 1 to 6 of 6

Thread: .NET MDGMessage

  1. #1

    Question .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!
    Last edited by KasumiL5x; 06-24-2015 at 08:58 AM. Reason: Fixed link to forum post.

  2. #2
    program Theodox's Avatar
    Join Date
    Mar 2012
    Location
    Seattle
    Posts
    1,107

    Default

    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.

  3. #3

    Default

    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.

    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.

  4. #4

    Default

    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-p...ge/m-p/6231404
    At the time of writing, I contacted Autodesk Support, and they still have no "official word" on the bugfix.

  5. #5
    undefined
    Join Date
    Dec 2014
    Posts
    1

    Default

    Quote Originally Posted by KasumiL5x View Post
    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-p...ge/m-p/6231404
    At the time of writing, I contacted Autodesk Support, and they still have no "official word" on the bugfix.
    So how did you manage to check if a node was created or removed?

  6. #6

    Default

    Quote Originally Posted by dev48 View Post
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •