Python Nodes and Scripts
While the core part of OmniGraph is built in C++ there are Python bindings and scripts built on top of it to make it easier to work with.
Importing
The Python interface is exposed in a consistent way so that you can easily find any of the OmniGraph scripting
information. Any script can start with this simple import, in the spirit of how popular packages such as numpy
and pandas
work:
import omni.graph.core as og
Using this module you can access internal documentation through the usual Python mechanisms:
help(og)
Bindings
The first level of support is the {ref}`Python Bindings<ext_omni_graph> which provide a wrapper on top of the C++ ABI of the OmniGraph core. These have been made available from the same import to make user of all OmniGraph functionality consistent. When you are programming in Python you really don’t need to be aware of the C++ underpinnings.
The bound functions have all of the same documentation available at runtime so they can be inspected in the same way you would work with any regular Python scripts. For the most part the bindings follow the C++ ABI closely, with the minor exception of using the standard PEP8 naming conventions rather than the established C++ naming conventions.
For example a C++ ABI function getAttributeType
will be named get_attribute_type
in the Python binding. This was
primarily done to deemphasize the boundary between Python and C++ so that Python writers can stick with Python
conventions and C++ writers can stick with C++ conventions.
As the Python world doesn’t have the C++ concept of an interface definition there is no separation between the
objects providing the functionality and the objects storing the implementation and data. For example in C++ you
would have an omni::graph::core::AttributeObj
which contains a handle to the internal data and a
reference to the omni::graph::core::IAttribute
interface definition. In Python you only have the og.Attribute
object
which encapsulates both.
The One Thing You Need
A lot of the imported submodules and functions available are used internally by generated code and you won’t have much occasion to use them. You can explore the internal documentation to see if any look useful to you. The naming was intentionally made verbose so that it is easier to discover functionality.
One class deserves special attention though, as it is quite useful for interacting with OmniGraph.
import omni.graph.core as og
controller = og.Controller()
The Controller
class provides functionality for you to change the graph
topology, or modify and inspect values within the graph.
Take a tour of how to use the controller with this how-to documentation