keywords: Houdini, Python Scripting Notes, Hython

Python Command Line

How to trigger button click event in python
import hou
vat = hou.node('/out/vertex_animation_textures1')
vat.setParms({"exportpath": "$HIP/export/test001"})

print('vat baking begin!')
vat.parm("renderall").pressButton()
How to execute python script file in command line interface
"""
A simple script to kick off a certain ROP remotely, optionally
with a given framerange.
Usage: hython path/to/script/houBatch.py /path/to/hipfile /hou/path/to/rop
TODO: Add options for multiple ROPs, hperf.
"""
import hou, sys

# Load the hip file
hou.hipFile.load(sys.argv[1])

# If framerange option, set it
#if sys.argv[3]:
#    hou.parmTuple( "%s/f" %(sys.argv[2]) ).set((sys.argv[3],sys.argv[4],1.0))

# Start the render
hou.node(sys.argv[2]).render()

# When finished, exit
sys.exit(0)

houBatch.py
https://gist.github.com/crydalch/3167162
How to write hbatch command
https://www.sidefx.com/forum/topic/37895/

Python in Node

How to print frame number?
node = hou.pwd()
geo = node.geometry()

print("frame:", hou.frame())

Issues

Unable to open hip file

Error:

C:\scripting>hython vat_rendering_02.py "C:\scripting\test.hip"
Traceback (most recent call last):
File "C:\scripting\vat_rendering_02.py", line 4, in <module>
	hou.hipFile.load("C:/ws_houdini/scripting/test.hip")
File "C:\PROGRA~1/SIDEEF~1/HOUDIN~1.303/houdini/python3.9libs\hou.py", line 52084, in load
	return _hou.hipFile_load(self, file_name, suppress_save_prompt, ignore_load_warnings)
hou.OperationFailed: The attempted operation failed.
Unable to open file: C:/ws_houdini/scripting/test.hip

Caused by:
hip file was renamed.

Solution:
Rename hip file name to original name named on creation.

Tutorials

Youtube Tutorials

Houdini Python - scripts on disc, button callback scripts, envs, packages, kwargs, menu scripts
https://www.youtube.com/watch?v=YCxzwIWnzUY

Python & Nodes in Houdini || Exploring Houdini
https://www.youtube.com/watch?v=yRx47kQ39eQ

[TALK] Python Scripting - Houdini
https://www.youtube.com/watch?v=CxoVzsxiruY

[TALK] Just Pipeline Things - Houdini
https://www.youtube.com/watch?v=gOdRQsAjQWk

Houdini Python
https://ikrima.dev/houdini/basics/hou-python/

Python & Parameters in Houdini
https://www.youtube.com/watch?v=2m5BYWTrzVY

Blogs & Documents

Houdini Python Scripts for Button Pushing
https://www.artstation.com/blogs/hinsunlee/L00y/houdini-python-scripts-for-button-pushing

Python for artists
https://github.com/kiryha/Houdini/wiki/python-for-artists


“As far as we can discern, the sole purpose of human existence is to kindle a light of meaning in the darkness of mere being.” ― Carl Gustav Jung