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:
GetLastError(): Returns, as a string, the error message associated with the last error encountered while running the Init(), Execute(), or ExecuteFile() methods.
throwOnError keyword argument: Controls whether MAXScript throws a runtime exception if an error occurs while running a method. If set to true, you always obtain a return result code of \#success because, in all other cases, a runtime exception would be thrown. It would be up to the script writer to make the call within a try/catch in order to handle the exception.
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.
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:
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).