Houdini: Jump to Material

Hi!
If the scenes get more and more complicated, material selection gets time-consuming, too. To speedup the selecting and navigating networks, I’ve build a shelf tool, that lets you jump directly to the corresponding material of an object. Please have look at my video. I’m explaining the installation and functionality. Hopefully that makes your navigation, during the shading process more comfortable.

  
#Import Modules
import toolutils
import hou

#Set Variables
selected_node = ""

#Define type arrays
MAT_Detect = ["redshift::Material","redshift_vopnet","principledshader::2.0","materialbuilder","arnold::standard_surface", "arnold_materialbuilder"]
Sel_Detect = ["geo","instance"]

#Get the Selected Nodes
selected = hou.selectedNodes()

#Check if there is something selected 
if selected:
    #Compare first selected objects type with the valid object types
    if selected[0].type().name() in Sel_Detect:
        #Set the selected node. Just the fist is valid
        selected_node = selected[0]
    #Force the user to select an object, if the current doesn't match the selection type
    else:
        #Clear the selection
        hou.clearAllSelected() 
        #Promt the user to select an new object
        prompt = toolutils.selectionPrompt(hou.objNodeTypeCategory())
        scene_viewer = toolutils.sceneViewer() 
        selected_objects = scene_viewer.selectObjects(prompt)
        #Check if an object is selected
        if selected_objects:
            #Set the first selected node to variable
            selected_node = selected_objects[0]
        else:
            #Output an Error
            hou.ui.displayMessage("Nothing Selected")    
#Force the user to select an object, because nothing is selected
else:
    #Promt the user to select an new object
    prompt = toolutils.selectionPrompt(hou.objNodeTypeCategory())
    scene_viewer = toolutils.sceneViewer() 
    selected_objects = scene_viewer.selectObjects(prompt)
    #Check if an object is selected
    if selected_objects:
        #Set the first selected node to variable
        selected_node = selected_objects[0]
    else:
        #Output an Error
        hou.ui.displayMessage("Nothing Selected")
    

#Check if the selected_node variable is not empty
if selected_node:
    #Compare selected_node's type with the valid object types
    if selected_node.type().name() not in MAT_Detect :
        #Convert Releative Pathes to Absolute Pathes
        matPath = selected_node.parm("shop_materialpath").eval()
        #Set the targetpath to the node variable
        node = selected_node.node(matPath)
        #Check if node is valid
        if node:
            #Look for child Objects
            if node.children():
                #If there are children, replace node with the fist child
                node = node.children()[0]
        else:
            #Output an Error
            hou.ui.displayMessage("Empty material path")
         
    else:
        node = selected_node
        #Look for child Objects
        if node.children():
            node = node.children()[0]

    #Check if the material node exists
    if node:        
        #Set some Variables
        pane = ""
        index = 0
        #Loop over the active panes
        while pane is not None:
            #Search for the first network editor
            pane = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor, index) 
            #Loop over the panes
            if pane is not None:
                #Get the current state
                ID = pane.linkGroup()
                #Looking for Linkgroup1
                if str(ID) == "paneLinkType.Group1":
                    targetPane = pane
                    switchorselect = 1
                #Looking for FollowSelection
                if str(ID) == "paneLinkType.FollowSelection":
                    targetPane = pane
                    switchorselect = 0
                #Looking for Pinned
                if str(ID) == "paneLinkType.Pinned":
                    targetPane = pane
                    switchorselect = 2
            index += 1
       
        #If there is a PaneType Group1 
        if switchorselect == 1:
            #Set the current Node
            targetPane.setCurrentNode(node)
        #If the PaneTypeState is set to Follow selection
        if switchorselect == 0:
            #Selet the material
            node.setSelected(True, clear_all_selected=True)
        #If the PaneTypeState is set to Pinned
        if switchorselect == 2:
            #Retun an errror
            hou.ui.displayMessage("The PaneType is set to Pinned")

Merge Objects into new Geometry

Hey! long time no post. But, now it’s time to post some stuff again. The first small script I want to share is a script, that has been handy during the last productions. It merges a geo object selection to an new geo and adds it’s material as primitive material. Maybe you were asking, why we sometimes are working like this. Houdini doesn’t display instanced subnets in the viewport and redshift doesn’t render instanced subnets. This is a workaround to fully instance subnet/objects in the viewport and at rendertime. Sure this is just a workflow for small assets, but for smaller products that need to be instanced this can be a solution. Also If you have to do some multi object editing. :).

import hou

#Get Houdini Selection
oSelection = hou.selectedItems()
#Create an empty List
oAllObjsforSubnet = []
#Create an empty Counter
counter = 0

#Check if the selection is empty
if oSelection:
    #The the obj context to the variable obj
    obj = hou.node("/obj")
    #create a new Geo Node on /obj level
    newNode = obj.createNode("geo", str("merged_geo"))
    #Delete the build in File node of the new Geo
    newNode.children()[0].destroy()
    #Create the hero merge node
    oMergeNode = newNode.createNode("merge")
    #Loop over the selected node
    for oNode in oSelection:
        #Check if the type is geo
        if oNode.type().name() == "geo":
            #Create an Obeject Merge node
            currentOBJMerge = newNode.createNode("object_merge")
            #Set the path to the base obj
            currentOBJMerge.parm("objpath1").set(oNode.path())
            #Check if there is an Material assigned
            if(oNode.evalParm("shop_materialpath") != ""):
                #Create a SOP materail node
                currentMaterial = newNode.createNode("material")
                #Convert relative Pathes to absolute pathes
                relPath = oNode.evalParm("shop_materialpath")
                relNode = oNode.node(relPath)
                fullpath = relNode.path()
                #Fill in the right materail path
                currentMaterial.parm("shop_materialpath1").set(fullpath)
                #Connect the current obj merge node the the materail node
                currentMaterial.setInput(0,currentOBJMerge)
                #Connect the material node the the hero merge node
                oMergeNode.setInput(counter,currentMaterial)     
            #If there is no Material assigned
            else:
                #Connect the Object Merge to the 
                oMergeNode.setInput(counter,currentOBJMerge)     
            #Increase the ounter, for the next merge node port
            counter +=1
    #Set the diplay Flag
    oMergeNode.setDisplayFlag(True)