Network Editor, remember the previously flagged node and unflag to it

I like to walk through the nodes and preview different states of the stream. Houdini has its own logic to “unflag” the Display Flag. It doesn’t jump back to its last position. I customized my own unflagging to the previously flagged node. If you like it, you may use my script (and hotkey it). Or you may customize it to fit your needs, for example always unflag to the last node.

import hou
import toolutils

parm_pane = hou.ui.curDesktop().paneTabOfType(hou.paneTabType.Parm)
parmnode = parm_pane.currentNode()
containername = parmnode.parent().name()

nodetype = "multiflag"

if hou.sopNodeTypeCategory() == parmnode.parent().childTypeCategory():
    nodetype = "singleflag"

if hou.dopNodeTypeCategory() == parmnode.parent().childTypeCategory():
    nodetype = "singleflag"


################################
## unflag to the last flagged ##
################################


if nodetype == "singleflag":

    # get this
    if len(hou.selectedNodes()) == 0:
        thisnode = parmnode
    else:
        thisnode = hou.selectedNodes()[0]
    thispath = thisnode.path()

    # get last
    lastpath = hou.getenv("unflagged", thispath)
    try:
        #node exists
        if hou.node(lastpath).parent().name() != containername:
            lastpath = thispath
    except:
        #node was deleted / renamed
        lastpath = thispath
    
    # get flag
    flagpath = hou.getenv("flag", thispath)
    try:
        #node exists    
        if hou.node(flagpath).parent().name() != containername:
            flagpath = thispath
    except:
        #node was deleted / renamed
        flagpath = thispath

        
    try:
        flag = hou.node(thispath).isDisplayFlagSet()
    except:
        flag = 2
        

    if flag == 0 :
    
        # setting clean
        setpath = thispath
        unflag = flagpath
        hou.putenv("unflagged", unflag )

        # set
        hou.putenv("flag", setpath )    
        setnode = hou.node( setpath )
        setnode.setDisplayFlag(True)

    if flag == 1 :
    
        # setting flagged
        setpath = lastpath
        unflag = thispath
        hou.putenv("unflagged", unflag )

        # set
        hou.putenv("flag", setpath )    
        setnode = hou.node( setpath )
        setnode.setDisplayFlag(True)

    

################################
#####  not SOP, just swap  #####
################################

if nodetype == "multiflag":

    # none is selected
    if len(hou.selectedNodes()) == 0:
        parmnode.setDisplayFlag(not parmnode.isDisplayFlagSet())
        
    # for all selected    
    for node in hou.selectedNodes():
        try:
            node.setDisplayFlag(not node.isDisplayFlagSet())
        except:
            hasnoflag = True

 

Leave a Reply

Your email address will not be published. Required fields are marked *