Is there a way to get an active Network Editor pane in Python?
For example, if we call a shelf tool when the cursor is over a Network Editor, we can get the pane with:
pane=kwargs['pane']
However, what if the shelf tool is called on another pane (e.g. a Scene Viewer)? In this case, how could we get an active Network Editor (if exists) pane in Python?
What if there are multiple Network Editor? I checked the doc and there is an indexparameter... but there is no function that returns the total number of Network Editor.
So how could I iterate over all Network Editor? Just increase the index until it returns None...?
Yes, that’s one way to do it — incrementing the index until it returns None.
In my code, I usually try to get the pane under the cursor first, and if it’s not the type I’m looking for, I fall back to getting the first instance like this:
defgetPaneTabUnderCursorOrFirstInstance(paneType):""" Utility function to retrieve a pane tab of a specific type. Tries to get the pane tab under the cursor first. If none is found, falls back to the first instance of the specified pane type in the current desktop. Args: pane_type (hou.paneTabType): The type of pane tab to search for. Returns: hou.PaneTab or None: The found pane tab of the specified type or None if not available. """desktop=hou.ui.curDesktop()paneTab=None# Try to get the pane tab under the cursorpane=hou.ui.paneTabUnderCursor()ifpaneandpane.type()==paneType:paneTab=paneelse:# Fallback to the first instance of the specified type in the desktoppaneTab=desktop.paneTabOfType(paneType)returnpaneTab
That's usefull if you trigger a script from within the paneTab you're after. Or you run some polling routine that keeps track which paneTab/type had the last focus.
Alternatively you can get the size of the paneTab and assume the largest one is the main one.
I know of paneTabUnderCursor(), but my use case is to do something with Network Editor when I'm modeling in Scene Viewer.
I guess iterating over all of them and check 1. the cdis the same as current Scene Viewer 2. if multiple matches then choose the largest one. is the way to go.