Python in Houdini
- PySide2 in Python 2.7 is built-in with houdini
- Python Access method:
- Python background shell:
- Alt+Shift+P: bring out float copy of Python Shell
- other Python shell can be brought out from panel menu
- houdini can have multiple independent python shells inside, unlike single ScriptEditor in Maya
- Python Source Editor (for temp test use only)
- works more like ScriptEditor's editor panel, only output to current top Python Shell.
- its function code is wrapped in a namespace “hou.session”
- its function code is stored with the hip file (it's file session based, not globally)
Technique Section
Tutorial Reference
- Python masterclass for houdini: https://vimeo.com/14612897
UI operation
- alert message
hou.ui.displayMessage('cool')
setting
- get current frame
hou.frame()
- add variable to hou's global() dictionary
hou.expressionGlobals()['myVal'] = 2018
Network Editor
- get network editor
net_edit = hou.ui.paneTabOfType(hou.paneTabOfType.NetworkEditor)
- move node
curNode.setPosition([0,0])
- color node
curNode.setColor(hou.Color(1,0,0))
Node Operation
- Node access
curNode = hou.node('/obj/geo1') # get node by name path like in Nuke(hou.SopNode) curNode.name() # node name curNode.path() # node path curNode.children() # node's inside nodes curNode.parm('tx').eval() # node's attribute's value (hou.Parm)
Houdini Asset
- parm template operation
print( hou.parm('/obj/assetNode/attr').parmTemplate().asCode() ) # get build script tabs = asseNode.parmTemplateGroup().entries() # get list of tabs of attr parmList = tabs[0].parmTemplates() # all the parm entries
Houdini HScript
- Hscript in Houdini = Mel in Maya, you can warp them around similarly
- you can use Hscript in python as well
- hou.hscript()
- hou.hscriptExpression()
- hou.expandString() # get hscript variable in python
- you can also get local variable with lvar()
- in houdini Python shell, you can directly access hscript by type % at start
Houdini inline C++
- you can create a in-line one-time compile C++ code in a python script to speed up heavy-calculation part
Houdini RPC
- socket based XML passing and commanding
- new one called HRPyC, old one is houxmlrpc
Houdini Python lib
- default by python versions: $HFS/houdini/python0.0libs