Tag Archives: Code

Add a switch to selected Houdini node

Here is a quick way to add a switch to currently selected Houdini Node.
For further improvements it would be great to have switch input exposed to parent HDA’s interface.
Also an option to have auto-Null input to switch sop.
i.e. “Switch to nothing” mode.

def addSwitchForDebug(self, parentOp = ""):
	Add switch op to bypass selected node and expose switch input to the parent.

	currentSel = hou.selectedNodes()
	if len(currentSel) == 1:
		current = currentSel[0]
		opName = "switch"
		parentNode = hou.node(current.path()).parent()

		# Get inputs and outputs
		outNodes = current.outputs()
		inNodes = current.inputs()

		#Create switch
		newNode = current.createOutputNode(opName)
		newNode.setName(opName, True)

		# Set correct inputs to switch node
		if len(inNodes) > 0:

		# Insert switch between current and its immediate output node
		if len(outNodes) > 0:
			currentOut = outNodes[0]