This section describes how to use the 3ds Max MaxPlus Python API.
MaxPlus is not supported under Python 3. Scripts that use MaxPlus APIs need to be converted to use the equivalent pymxs APIs to run under Python 3. See Using pymxs.
The 3ds Max MaxPlus Python API is built on top of and based on the 3ds Max C++ SDK. Global functions, and functions from static interfaces such as the Interface
class and the derived classes (Interface7
and so forth), have been regrouped into smaller classes based on functionality, such as: RenderSettings
, Animation
, Grid
, or Snaps
. Refactoring was performed for several functionalities in global functions, as well as the core interfaces into the INode
class. The goal was to create an API that is more intuitive.
help()
and dir()
are two of the most useful functions in Python.
For example, you can obtain a list of attributes for a class (list of methods, variables) using help
as follows:
import MaxPlus
help(MaxPlus.Asset)
In your MAXScript Listener window, you will obtain a list of all attributes for the Asset
class.
To obtain a list of attributes for an object, you can also use the Python built-in dir()
function. The dir(object)
function, when passed an argument (object), returns a list of attributes for the object.
For more information regarding these two functions, as well as other tips and tricks, see MaxPlus Tips and tricks.
In the 3ds Max environment, data sent from a Python script to sys.stdout
(for example, by using print
) or to sys.stderr
is redirected to the MAXScript Listener window.
Note that 3ds Max is not thread-safe, so printing to the Listener Window from threads other than the main thread can cause the application to crash, and is not recommended. If you are using multiple threads in your script, you can disconnect sys.stdout
and sys.stderr
from the Listener using these commands at the beginning of your script:
sys.stdout = _old_stdout
sys.stderr = _old_stderr
A property is an attribute that is the equivalent of a Get()
and Set()
method pair. You can simply access the attribute to query or set its value.
There exist also read-only properties, which are the equivalent of their corresponding Get()
methods.
For example, the ParameterBlock.GetName()
method has a corresponding ParameterBlock.Name
property.
In the demoApplyMaterial.py
example:
m = MaxPlus.Factory.CreateDefaultStdMat()
m.Ambient = color
m.Diffuse = color
is equivalent to:
m = MaxPlus.Factory.CreateDefaultStdMat()
m.SetAmbient(color)
m.SetDiffuse(color)
In the Python API Reference documentation, there are attribute descriptions along the lines of:
tuple Type = _swig_property(GetType)
In this case, Type
is a property that you can query to obtain the Type
value, and its corresponding method is GetType()
.
Constants are represented in the Python API along the lines of ColorSelection = _MaxPlus.Colors_ColorSelection
as a result of swig.