This example accesses the main MDL SDK interface, queries the version interface, and then starts and shuts down the MDL SDK API.
The MDL SDK is written in C++ and the Python bindings are generated by SWIG
and follow the same naming conventions as the native API. Multiple words are concatenated with _
to form identifiers. Function names are all lower case, while types and classes start with one initial upper-case letter.
The pymdlsdk.py
module contains all required classes and functions of the bindings.
Analogue to the C++ examples, the Python bindings come with a helper function to loads the neuray library and calls their only public access point, the mi_factory() function. This helper function load_and_get_ineuray()
accepts a parameter of type string to specify the filepath of the native libmdl_sdk.dll
(or libmdl_sdk.so
). The file extension itself can be omitted to not require platform dependent Python code. Passing an empty string will look for libmdl_sdk
in the PATH
, LD_LIBRARY_PATH
, or DYLD_LIBRARY_PATH
depending on the platform.
Calling the helper function returns mi::neuraylib::INeuray interface from which all other data structures and functions can be accessed. The mi::neuraylib::INeuray interface can only be accessed once per process.
Except for trivial classes, such as the math vector class, all classes in the MDL SDK API are implemented using interfaces. See Library Design for an explanation. Interfaces are created and destroyed by the MDL SDK API. They implement reference counting for life-time control and cheap copying operations. Interface names start with an I
prefix.
The Python bindings take care of the reference counting as long as the context manager pattern is used or objects are released explicitly (see Reference Counting).
The context managers also work in places where the native API would return a nullptr. In the Python bindings these null-pointers are not represented by None
. Instead, an object is always returned. To check if an MDL object is valid, all interface provide an is_valid_interface()
function.
The mi::neuraylib::INeuray interface is used to start and shut down the MDL SDK API. The API can only be used after it has been started (and before it has been shut down). Startup does not happen during the mi_factory() or load_and_get_ineuray
call because you might want to configure the behavior of the API, which has to happen before startup.
The status of the API can be queried using the mi::neuraylib::INeuray::get_status() method.
Finally, you have to shut down the MDL SDK API. At this point, you should have released all interface objects except the main mi::neuraylib::INeuray interface.
Source Code Location:
examples/mdl_python/start_shutdown/example_start_shutdown.py