Troubleshooting 3ds Max Python API
Why doesn't my CPython extension module load?
Check if your extension module was built and linked against a different version of Python. In order to use a CPython module with Python in 3ds Max, you must compile the CPython binaries against Python version 3.7. See Python extension libraries for more information.
I am trying to install an extension module but 3ds Max Python is not detected by the installer
Update the registry or manually install the module. Often modules support installation via manual steps or a Python module (for example, the Python "easy_install" module (http://pythonhosted.org/distribute/easy_install.html). See also Python extension libraries for more information.
I set a property but do not see the expected result
In Python, if you misspell a property when assigning it, a new field is added to the object as a result - for example: MyClass.fOotball = x, or worse yet: MyClass.GetValue = 42. It is legal to add or replace fields on an object at run-time; therefore no error occurs. The safest way to set a property is to use a Set
function, for example: render.SetWidth(640).
I run my script and it works. However, when I restart 3ds Max and run the script again, I get an error.
When you run any Python code that affects the global environment (for example, importing a module), those settings persist during your session of 3ds Max. A common mistake is to rely on a module that was imported by another script, or to call a function that was created by another script.
I have a script (for example, "MyLibraryModule") that is imported by another script (for example, "MyProgram), but after I make changes to MyLibraryModule, the changes do not seem to take effect the next time I run "MyProgram".
Use the reload(MyLibraryModule)
command to force Python to reload that module.
Common issues and their workarounds
-
When
sys.exit()
is used to exit Python, it raises aSystemExit
exception. If an uncaught exception is raised in Python, it is reported to the MAXScript Listener window as an error, even though no error actually occurred. To avoid having an error being reported in the MAXScript Listener window bysys.exit()
, you can use thetry
andexcept
statements as follows:try: import sys print \'goodbye world\' sys.exit() # Safe way to leave program at any point and allow objects and resources to be cleaned up. # Prevent 3ds Max from reporting a system exit as an error in the listener. except SystemExit: pass
-
If you import a module in a script, the module remains "imported" even after you finish executing your script and start executing a different script. Any names added to the global namespace will also remain from script execution to script execution. These only persist per session of 3ds Max, however, and you can workaround this by exiting and reloading 3ds Max.
-
When creating an instance of
QApplication()
, do not useapp = QApplication([])
, use instead:app = PySide2.QtCore.QCoreApplication.instance() if not app: ...
to avoid a potential crash.
Note Troubleshooting tips for PySide2 also apply to PyQt.
-
Some modules require that you set
sys.argv = ['']
before you use them; for example,app = QtGui.QApplication(sys.argv)
. -
Module names (for example,
pymxs
) and built-in functions (for example,dir
) can be re-assigned to anything. This is especially a problem with global variables since it can break other scripts, but is acceptable within the scope of a function. -
The
sys.path
does not contain the executing script path. This is by design. To get the path of the currently executing script, use the__file__
constant.