Python: How to get the active Network Editor pane?

   762   5   3
User Avatar
Member
643 posts
Joined: 8月 2019
Offline
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?
User Avatar
Member
4970 posts
Joined: 2月 2012
Offline
Hi,

There’s no concept of an “active” pane, but you can get a Network Editor in the current layout like this:

editor = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
User Avatar
Member
643 posts
Joined: 8月 2019
Offline
animatrix_
Hi,

There’s no concept of an “active” pane, but you can get a Network Editor in the current layout like this:

editor = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)

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...?
Edited by raincole - 2025年5月4日 05:41:02
User Avatar
Member
4970 posts
Joined: 2月 2012
Offline
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:

def getPaneTabUnderCursorOrFirstInstance(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 cursor
    pane = hou.ui.paneTabUnderCursor()
    if pane and pane.type() == paneType:
        paneTab = pane
    else:
        # Fallback to the first instance of the specified type in the desktop
        paneTab = desktop.paneTabOfType(paneType)
    
    return paneTab
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
User Avatar
Member
287 posts
Joined: 7月 2013
Offline
See "paneTabUnderCursor()"

https://www.sidefx.com/docs/houdini/hom/hou/Desktop.html [www.sidefx.com]

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.
More code, less clicks.
User Avatar
Member
643 posts
Joined: 8月 2019
Offline
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.

Thank both of you for the answers!
Edited by raincole - 2025年5月4日 19:27:17
  • Quick Links