Skip to content

Instantly share code, notes, and snippets.

@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:
@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 / set_read_only_parm.py
Last active August 9, 2022 19:46
Context manager for unlocking/locking parameters
import contextlib
@contextlib.contextmanager
def set_read_only_parm(parm):
if not isinstance(parm, (hou.Parm, hou.ParmTuple)):
return
# Unlock the parm
parm.lock(False)
@jamesrobinsonvfx
jamesrobinsonvfx / expandcollapsestringdemo.py
Created February 20, 2022 22:55
Expand / Collapse String Parameter Snippets
"""Disable When / Hide When Expressions
Used to control parameter visibility.
"""
# Hide When Expression
{ expanded == 1 }
# Hide When Expression (multiparm)
@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 / parm_menu_list.py
Last active January 25, 2022 11:00
Double up a list for Houdini menu parameter scripts
items = ["raspberry", "grape"]
return [x for y in [(x, x) for x in items] for x in y]
# ["raspberry", "raspberry", "grape", "grape"]
# Or fancier
[x for y in [(x, x.title()) for x in presets] for x in y]
# ["raspberry", "Raspberry", "grape", "Grape"]
@jamesrobinsonvfx
jamesrobinsonvfx / ftrimify.py
Last active January 22, 2022 04:41
Wrap an ftrim() function around channel refs
import re
import hou
def ftrimify(parm):
"""Wrap an ftrim() function around channel refs.
Args:
parm (hou.Parm): Parameter to add ftrim()s to. Should be a
@jamesrobinsonvfx
jamesrobinsonvfx / wildcard_camelcase.hscript
Last active September 24, 2021 18:14
Wildcard for camelCased paths in Houdini parameters
// Match forearm, leftArm, and arm
@name=*[aA]rm
@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 / 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
)