Houdini - Python Snippets
String
Regex
Replace
import re
REGEX_TRAILING_DIGITS = re.compile(r'^([a-zA-Z_]*?)[0-9]*$')
node = hou.pwd()
geo = node.geometry()
for prim in geo.prims():
mat_name = prim.attribValue('shop_materialpath')
m = REGEX_TRAILING_DIGITS.match(mat_name)
if m:
capt_grp = m.groups()[0]
prim.setAttribValue('shop_materialpath', capt_grp)
Parms
Add
Button
Add a button to a cop network that when it is pressed will render a child node called “rop_cop1”. It seems that the commented out line is not necessary? Seems to do the same as the 2 lines above. The lines are from when I run an asCode() on the node that had the setup I wanted.
snippet = "hou.node('.').node('rop_comp1').parm('execute').pressButton()"
parm_template_group = node.parmTemplateGroup()
parm_template = hou.ButtonParmTemplate("render", "Render")
parm_template.setScriptCallback(snippet)
parm_template.setScriptCallbackLanguage(hou.scriptLanguage.Python)
# parm_template.setTags({"script_callback": snippet, "script_callback_language": "python"})
parm_template_group.append(parm_template)
node.setParmTemplateGroup(parm_template_group)