Executing Python from MAXScript

Python interface methods

The MAXScript Python interface contains methods for using Python in MAXScript. If you run

showinterface python

in MAXScript, you obtain, in the MAXScript Listener, a list of available methods. The following list describes these methods and arguments:

Importing and Using Python Libraries

Python libraries can be imported and used in MAXScript, using Python.Import(). See the "Executing Python from MAXScript" topic in the MAXScript Help for more information.

Limitations

Because of the way Python is wrapped in MAXScript, methods and functions bound to Python execution frames will not work as expected, if at all. Some examples of calls that will not work via Python.import() include:

Executing Python from MAXScript

You can execute Python commands and statements (can be a single command/expression or a series of statements); or a Python script (for example, a .py script) from within MAXScript. Use the python.Execute and python.ExecuteFile commands respectively, as follows:

python.Execute "print 'hello'"

python.ExecuteFile "demoBentCylinder.py"

If you provide a full path using the ExecuteFile command; for example, as follows; 3ds Max looks for the Python file in the path provided.

python.ExecuteFile @"C:\Program Files\Autodesk\3ds Max 2015\scripts\Python\demoBentCylinder.py"

Otherwise, 3ds Max looks for the Python script under the following directories:

For example, 3ds Max would search under the following directories: userscripts\\python, userscripts\\startup\\python, scripts\\python, scripts\\startup\\python, and subsequently the windows paths.

The output of the results from scripts are printed to the MAXScript Listener window.

Note Python scripts run in MAXScript are not thread-safe. Python commands are always executed in the main 3ds Max thread. You should not attempt to spawn separate threads in your scripts (for example, by using the Python threading module).