Houdini Camera Auto Focus Distance Tool

Here’s a little tool to generate a focus null based on your selected camera. Let me know if there are any bugs because I literally type this in 20mins without checking much! Thanks and cheers!

# Author: Ronald Fong
# Date: 29 Sep 2021
# Usage: Add this as a shelf tool. With a camera selected in the obj context, use this tool to generate a focus nul, and automatically sets the focus of the camera to the distance between the camera and the nul.
# Feature 1: Names the focus node based on the selected camera node
# Feature 2: Selects the focus node for user convenience
# set root
obj = hou.node("/obj")
# define nodes and create focus nul
selected_node = hou.selectedNodes()
cam_node = selected_node[0]
cam_node_name = str(cam_node) + "_focus"
focus_node = obj.createNode("null", cam_node_name)
# set camera focus code to focus nul
focus_code = "vlength(vtorigin(\".\",\"../" + cam_node_name + "\"))"
# layout nodes and select focus nul for user convenience
obj.layoutChildren(items=[cam_node, focus_node], horizontal_spacing=1, vertical_spacing=1)

Create File Cache and File nodes in Houdini

Here’s a tool to add filecache and file nodes to your selected node in SOPs geometry context. At Masonry Studios, we base our Houdini geometry caches and its version on the file name (which contains the version number) and the node name, which is the default in Houdini’s file cache node.

However avoid using the file cache’s “Load from Disk” option to load the geometry back in, because:

  1. It’s convenient for the file cache node’s “Geometry Path” to stay as the default un-evaluated relative path, in order to generate new caches based on the current file version
  2. If we load in the geometry based on this relative path, and we version up our working file, this relative path will fail.
  3. Hence, we find it quite an elegant solution to use a file cache and a file node separately. The file node points to the absolute evaluated “Geometry Path” of the file cache node and we’ve since successfully avoided the issue of broken links to caches.
# Author: Ronald Fong
# Date: 29 Sep 2021
# Usage: Add this as a shelf tool. With a SOP node selected, use this tool to quickly create a filecache and a cache node.
# Feature 1: Names the cache nodes based on your selected node
# Feature 2: File node will automatically be the evaluated absolute path of your filecache node
selected_node = hou.selectedNodes()
geo_node = selected_node[0].parent()
name = str(selected_node[0])
filecache_node = geo_node.createNode("filecache", ("filecache_" + name))
file_node = geo_node.createNode("file", ("file_" + name))
file_node.setInput(0, filecache_node)
filecache_node.setInput(0, selected_node[0])
filename = filecache_node.parm("file").eval()