The following tips may be helpful when moving from Hscript to Python:
See the “replaced by” sections in the Hscript command and expression help to find the equivalent functionality in the
houmodule.If a desired
houmodule function or method is not yet implemented, you can find the Hscript equivalent in the “replaces” section of thehoumodule help. You can call Hscript commands with hou.hscript, run expressions with hou.hscriptExpression, and evaluate Houdini variables with hou.expandString.You can easily run Hscript commands from an interactive Python shell (in Houdini or hython) by prefixing them with
%. For example:>>> %cd /out /out >>> %render mantra1
You cannot use % to run hscript commands from Python scripts.
The Python equivalent of the
hbatchprogram ishython.Take advantage of the language features that Python has over Hscript. Instead of cd'ing around like you would in Hscript, use variables to store hou.Node objects and and operate on those nodes. Write Python functions to reduce the amount of code you write.
If the
houmodule functions, methods, or classes are too verbose, create your own aliases. For example, you could write the following:>>> n = hou.node >>> hou.Node.p = hou.Node.parm >>> n("/obj/geo1") <hou.ObjNode of type geo at /obj/geo1> >>> n("/obj/geo1").p("tx") <hou.Parm tx in /obj/geo1>