With the release of the Subscription Advantage Pack for 3ds Max 2012 there have been significant enhancements to the exposure of 3ds Max SDK to .NET. Previously only a small subset of the 3ds Max SDK was exposed to .NET via the ManagedServices.dll. Now nearly all of the global functions and classes in the SDK can be accessed directly from .NET using the new Autodesk.Max.dll.
The Autodesk.Max.dll assembly is automatically generated from the 3ds Max SDK header files, so most of the functions and classes in the 3ds Max SDK are mapped to similarly named constructs in the DLL.
One of the easiest ways to become familiar with the contents of the DLL is to load it in the Visual Studio object browser. In the rest of this document we will review some key features of this assembly.
You may also consult 3ds Max SDK Learning Path - Lesson 7: Writing.NET Plug-ins for more information on using the Autodesk.Max.dll .NET assembly.
Before we can do anything interesting with the Autodesk.Max.dll we need a handle to an instance of the "IGlobal" interface. This interface provides access to all of the global functions and variables in the 3ds Max SDK. You might use this from a function as follows:
IGlobal Global = Autodesk.Max.GlobalInterface.Instance; IInterface13 Interface = Global.COREInterface13;
Note the presence of a property "COREInterface13" instead of the expected function "GetCOREInterface13()". Consult the "Functions to Properties" section below for more information.
The 3ds Max SDK from C++ uses classes exclusively. What are called "interfaces" in the C++ SDK, are actually "abstract classes". That means they are instances of classes with one or more pure virtual functions. In Autodesk.Max.dll almost every class has a corresponding interface that is used where the class might be expected as an argument type or return type. For example we used IAnimatatable instead of Animatable. The DemoTeapot() function in the next example demonstrates this issue.
The Autodesk.Max.dll maps certain methods in the 3dsMax C++ SDK to .NET properties according to the following rules:
The following code shows how the COREInterface property is used instead of the GetCOREInterface() function.
void DemoTeapot(IGlobal global) { IGlobal global = Autodesk.Max.GlobalInterface.Instance; //note that global will be an instance of an abstract class. var intfc = global.COREInterface13; IClass_ID cid = global.Class_ID.Create((uint)BuiltInClassIDA.TEAPOT_CLASS_ID, (uint)BuiltInClassIDB.TEAPOT_CLASS_ID); object obj = intfc.CreateInstance(SClass_ID.Geomobject, cid as IClass_ID); if (obj == null) throw new Exception("Failed to create a teapot!"); IINode n = global.COREInterface.CreateObjectNode((IObject)obj); IObject iobj = (IObject)obj; IParamArray ps = iobj.ParamBlock; ps.SetValue(0, global.COREInterface.Time, 20.0f); n.Move(global.COREInterface.Time, global.Matrix3.Create(), global.Point3.Create(20, 20, 0), true, true, 0, true); }
In order to instantiate a specific type from the Autodesk.Max.dll we need to use properties of the IGlobal interface. For example in order to instantiate an instance of a Point3 you would write:
IPoint3 pt = Autodesk.Max.GlobalInterface.Instance.Point3.Create(20, 20, 0)
Note that IGlobal.Point3 is a property that returns an instance of an interface of type IGlobal.IGlobalPoint3. The IGlobalPoint3 type is a member type of the IGlobal type and has a Create() function that will return a Point3 instance.
In Autodesk.Max.dll default arguments are not supported. As a result, some functions require many more arguments than the 3ds Max SDK requires. You can look up the values that are used as default arguments in the 3ds Max SDK documentation.
Many macros (especially function macros) are not ported from 3ds Max SDK to .NET. Instead, you will have to figure out what the macro expands to and then use it directly. For example in C++ the following line:
EPoly13* epoly = GetEPoly13Interface( myObject );
EPoly13* epoly = (EPoly*)( myObject )->GetInterface( EPOLY13_INTERFACE );
IEPoly epoly = (IEPoly)myObject.GetInterface( EPOLY13_INTERFACE );
To do this easily, it is recommended to use the Visual Studio "Find in Files" feature to search the \maxsdk\include folder for the correct macro expansion. Alternatively you can use the C++ SDK documentation.
The Autodesk.Max.dll is found in the root directory of 3ds Max.
Not quite, though they share a common ancestor. Autodesk.Max.dll will likely continue to evolve in a different direction.
This functionality is not supported, and we strongly recommend against using it.
Try using the object browser to search for the name. If the name of a function starts with "Get" you should remove that. Note that many macros aren't carried over from the 3ds Max SDK, so you will have to expand those manually.
We do not recommend overriding these classes when creating plug-ins. Doing so may cause unexpected results.
This is an IntPtr that has a pointer to the unmanaged pointer of an object.
You can't use resource files in .NET. So use the ParamBlock2Flags.autoUI flag to have 3ds Max create the UI for you.