Tag Archives: Technical

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)
		newNode.setColor(Color.Default)

		# Set correct inputs to switch node
		if len(inNodes) > 0:
			newNode.setFirstInput(inNodes[0])
			newNode.setNextInput(current)

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

		newNode.moveToGoodPosition()


Advertisements