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.
Get the current graph and selection
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.getCurrentGraphSelection() 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.