The Python API is contained in the maxwell
module. Importing this module does not try to load the API, so it's safe to do it at any time. However, calling most functions can throw the maxwell.APILoadError
exception if the Maxwell plug-in is not loaded or cannot be opened. The only functions which can be called when Maxwell is not present are those that are static in the C++ API (e.g. the callback methods described above).
Most Python functions have identical return types and arguments as their C++ counterparts. Functions which return boolean values in the C++ API to indicate success or failure raise exceptions instead in Python. The Create* methods from MaxwellMayaAPI
are replaced by calling the constructors of the respective types directly. A few methods are changed so that they work in a manner which is better suited to the Python programming practices (e.g., the GetNumLayers()
and GetLayer(unsigned int index)
methods have been replaced by a single GetLayers()
method which returns a list of layers in the material). This documentation will describe the methods in a language-independent way, noting individual differences where they exist.
All the methods raise maxwell.Error
or an exception derived from it (this does not cover Python runtime errors, such as passing the wrong number of arguments to a function). The subclasses of this are:
APILoadError
: the Maxwell plug-in is not present or there's a mismatch between the Python API and the C++ API (the latter indicates an installation problem). The object contains a string description of the problem.ExporterStateError
: the function call is invalid in the current state of the exporter. For example, you can only create meshes when the exporter is running. The string value mentions the name of the failed function and the state in which it can be called.ParameterError
: an invalid parameter was passed, e.g. declaring that a mesh has 10 vertices and then only passing 9 inSetPositions()
.
maxwell.Error
is thrown directly (e.g. out of memory conditions, or I/O error while trying to read a material from a MXM file). The string value of the exception will contain a human-readable description of the error.