Autodesk.Max.dll

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 Lesson 7: Writing .Net Plug-ins for more information on using the Autodesk.Max.dll .NET assembly.

Accessing the services exposed by 3ds Max - the IGlobal Interface and Interface13

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.

Interfaces and Classes

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.

Functions to Properties

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);
    IAnimatable iobj = (IAnimatable)obj;
    IIParamBlock2 ps = iobj.GetParamBlock(0);
    ps.SetValue(0, global.COREInterface.Time, 20.0f, 0);
    n.Move(global.COREInterface.Time, global.Matrix3.Create(), global.Point3.Create(20, 20, 0), true, true, 0, true);
}

Instantiating types

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.

Default arguments

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.

Macros

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 );

expands to:

EPoly13* epoly = (EPoly*)( myObject )->GetInterface( EPOLY13_INTERFACE );

So using Autodesk.Max.dll:

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.

FAQ