Skip to content

Instantly share code, notes, and snippets.

@jamesrobinsonvfx
jamesrobinsonvfx / attrib_menu.py
Last active August 20, 2021 22:48
Python Attribute Menu
node = kwargs["node"]
return kwargs["node"].generateInputAttribMenu(
attrib_type=hou.attribType.Point,
data_type=hou.attribData.Float,
min_size=1,
max_size=3
)
@jamesrobinsonvfx
jamesrobinsonvfx / top_cook_cli.py
Created March 21, 2021 18:43
Cook Topnet on the Command Line
import hqueue.houdini as hq
node = hq.getNode("/obj/topnet1").displayNode()
node.executeGraph(False, True, False)
@jamesrobinsonvfx
jamesrobinsonvfx / houdini_version_package.json
Created April 25, 2021 04:02
Houdini Version in a Houdini Package
{
"path": "$HOME/cooltool/houdini{$HOUDINI_VERSION}"
}
@jamesrobinsonvfx
jamesrobinsonvfx / copy_parm_to_clipboard.py
Last active August 20, 2021 22:52
Action button script to copy the value of a parameter to the clipboard (linux)
"""Action button script."""
import os
if kwargs["shift"]:
# Copy evaluated parameter string
text = kwargs["parmtuple"][0].evalAsString()
command = "echo -n {0}| xclip -sel clip".format(text)
os.system(command)
else:
# Copy a reference to this parameter
@jamesrobinsonvfx
jamesrobinsonvfx / random_from_bitmask.h
Last active August 20, 2021 22:42
Pick a random value of a bitmask per point
int num_choices = 5;
int idx = floor(rand(i@id + 65536) * num_choices);
i@bitmask = int(pow(2, idx));
@jamesrobinsonvfx
jamesrobinsonvfx / set_viewer_to_cam.py
Created July 20, 2021 03:53
Set viewport to camera
import toolutils as tu
viewer = tu.sceneViewer()
viewports = viewer.viewports()
cam = hou.node("/obj/rendercam")
# There are always 4 viewports!
# https://www.sidefx.com/forum/topic/38171/#post-174454
for vp in viewports:
vp.setCamera(cam)
@jamesrobinsonvfx
jamesrobinsonvfx / rbd_to_instancepoints.h
Last active August 20, 2021 22:43
Convert RBDs (Fetch Packed Geometry from DOP network style) to instancepoints. Pretty sure this is lifted from one of Henry Foster (Toadstorm)'s odforce/sidefx forum replies.
// Get packed xform and pivot
matrix xform = getpackedtransform(0, i@ptnum);
vector pivot = primintrinsic(0, "pivot", i@ptnum);
// Orient for instancing
p@orient = quaternion(matrix3(xform));
// Crack pscale
vector scale = cracktransform(0, 0, 2, 0, xform);
f@pscale = avg(scale);
@jamesrobinsonvfx
jamesrobinsonvfx / first_last_filetime.py
Last active August 20, 2021 20:52
Quick 'n' dirty script to include as part of a custom cache node, or a shelf tool to calculate cache times for frame sequences (Python 3)
import math
import os
import re
def timedelta(file1, file2):
t1 = os.path.getmtime(file1)
t2 = os.path.getmtime(file2)
time = abs(t2 - t1) / 60.0
min = math.floor(time)
@jamesrobinsonvfx
jamesrobinsonvfx / multiparm_instance_index.py
Last active January 27, 2022 21:04
Easiest way to get multiparm instance index
# Callbacks
idx = kwargs["script_multiparm_index"]
# In a parameter expression
idx = evaluatingParm().multiParmInstanceIndices[0] # Returns a tuple. Will need subscript for the right level, and test for IndexError
# In a parameter expression, better
import re
idx = re.match(r".+(\d+)$", evaluatingParm().name()).group(1)
@jamesrobinsonvfx
jamesrobinsonvfx / toggle_manual.py
Last active March 9, 2023 20:32
Toggle Manual Mode in Houdini
def toggle_manual():
"""Toggle cook mode"""
current_mode = hou.updateModeSetting()
auto = (hou.updateMode.AutoUpdate, hou.updateMode.OnMouseUp)
toggle_cook = hou.shelves.tool("toggle_manual")
toggle_cook.setLabel("Auto Update")
if current_mode in auto:
hou.setUpdateMode(hou.updateMode.Manual)
toggle_cook.setIcon("MISC_cook")
elif current_mode == hou.updateMode.Manual: