Accessing graphs and selections
The SDApplication class contains some helpful methods that let you access the currently active graph, and the current selection within it.
import sd
## Get the application and UI manager object.
ctx = sd.getContext()
app = ctx.getSDApplication()
uiMgr = app.getQtForPythonUIMgr()
## Get the current graph.
g = uiMgr.getCurrentGraph()
print("The current graph is %s" % g)
## Get the currently selected nodes.
selection = uiMgr.getCurrentGraphSelectedNodes()
for node in selection:
print("Node %s" % node)
A graph displayed in a specific Graph view can be accessed using a graphViewID.
This method is useful when creating custom graph view toolbars. The Creating toolbars in Graph views sample in the Creating user interface elements chapter provides further details.
recommendation-more-help
dd48abc6-e399-43d2-9777-578ec70c5a23