Custom Callback Notifications in Autodesk 3DS Max

Discovering new things is awesome, especially by accident. This was the case when I was working with the Autodesk 3ds Max .NET SDK, as I was tasked to add a feature that required using a custom callback function.

Skip to the solution & code examples if you’re already familiar with 3ds Max.

Un(document)ed Territory

If you’ve worked with Autodesk 3ds Max long enough, you would know you can use MaxScript, Python, C# and C++ to interface with it. Unlike the former two languages, C++ & C# uses the 3ds Max SDK, which comes with extremely sparse documentation online, resulting in you trawling through a revolving door of redirects or 404 pages galore.

The only way to get code samples is to install the SDK from the 3ds Max disk image (I didn’t have this available and I strongly recommend doing this). But even then, the SDK has no .NET samples. Luckily, the C# codebase is structured nicely and well commented; a nice substitute.

Since the tool I worked on is written in C#, the DLL needed to use these notifications are in Autodesk.Max.dll (found in the installation directory) one can use a .NET disassembler to pry into the classes, methods, constants, etc. I stumbled across SystemNotificationCode.cs, a list of notification events defined in 3ds Max. Here is a small example on how to use it and below is a truncated list of example notifications (the full list is here)

public enum SystemNotificationCode : uint
{
    UnitsChange = 1,
    TimeunitsChange = 2,
    ViewportChange = 3,
    ...
    LayerHiddenStateChanged = 8193,
    LayerRenamed = 8194,
    InternalUseStart = 1879048192
}

If you look closely at that list, you will notice Custom1 to Custom7 notifications.

...
Custom1 = 4098,
Custom2 = 4099,
Custom3 = 4100,
Custom4 = 4101,
Custom5 = 4102,
Custom6 = 4103,
Custom7 = 4104,
...

It turns out you can use these as custom callback notifications. I was looking for documentation on this in the SDK and on Google. There really wasn’t anything related to calling these custom notifications. I had a hunch that these notifications are also built into 3ds Max, so it was a case of just trying it out.

Calling the Custom Callback Notification

To see what this looks like in action, below is a list of event notifications tied to their respective functions.

For example if you reset the whole scene in 3DS Max, SystemPreReset will be triggered before the scene gets reset and SystemPostReset will be triggered after the scene gets reset, causing our nicely named notifications onSystemPreReset and onSystemPostReset to be called.

To trigger the custom system notification CustomN, we have to turn to MaxScript for help. A very handy property of MaxScript is that it can interoperate with Python and .NET.


bn = (dotNetClass "Autodesk.Max.GlobalInterface").Instance.BroadcastNotification
bn (dotNetClass "Autodesk.Max.SystemNotificationCode").Custom3

Once this code runs, any function that is hooked onto Custom3 would execute. This function can be in MaxScript, Python, C# or C++.

That’s it really…

Code Examples

You’re not leaving empty handed! I’ve taken it upon myself to write 4 basic examples of calling custom notifications in MaxScript, Python, C# and C++; something akin to samples Autodesk should have provided.

Try it out yourself! the code is over on GitHub.

Instructions for installation and how to build/run the project are on the README.

(Or if you’re lazy just download the DLL (C#) / DLU (C++) from the releases section and follow the instructions.

© 2020 Wesley Hill

CC-BY-SA

JSON

ATOM

Privacy