Commands
Like other extensions, the OmniGraph extensions expose undoable functionality through some basic commands. A lot of the functionality of the commands can be accessed from the og.Controller object, described above.
OmniGraph has created a shortcut to allow more natural expression of command execution. The raw method of executing a command is something like this:
import omni.graph.core as og
graph = og.get_graph_by_path("/World/PushGraph")
omni.kit.commands.execute("CreateNode", graph=graph, node_path="/World/PushGraph/TestSingleton", node_type="omni.graph.examples.python.TestSingleton", create_usd=True)
The abbreviated method, using the constructed cmds object looks like this:
import omni.graph.core as og
graph = og.get_graph_by_path("/World/PushGraph")
og.cmds.CreateNode(graph=graph, node_path="/World/PushGraph/TestSingleton", node_type="omni.graph.examples.python.TestSingleton", create_usd=True)
However for most operations you would use the controller class, which is a single line:
import omni.graph.core as og
og.Controller.edit("/World/PushGraph", {
og.Controller.Keys.CREATE_NODES: ("TestSingleton", "omni.graph.examples.python.TestSingleton")
})
Tip
Running the Python command help(omni.graph.core.cmds) in the script editor will give you a description of all available commands.