Python in Houdini

  • PySide2 in Python 2.7 is built-in with houdini
  • Python Access method:
    1. 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
    2. 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

  • alert message


  • get current 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
  • color node
  • Node access
    curNode = hou.node('/obj/geo1') # get node by name path like in Nuke(hou.SopNode) # node name
    curNode.path() # node path
    curNode.children() # node's inside nodes
    curNode.parm('tx').eval() # node's attribute's value (hou.Parm)
  • 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
  • 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
  • you can create a in-line one-time compile C++ code in a python script to speed up heavy-calculation part
  • socket based XML passing and commanding
  • new one called HRPyC, old one is houxmlrpc
  • default by python versions: $HFS/houdini/python0.0libs