CreateScripts
From Odwiki
Operator Creation Scripts
When Houdini creates an operator it has the ability to run a node type specific script to perform operations on the newly created node. For instance, when you place a Geometry object, Houdini runs an existing geo.cmd script that handles the adding of all the rendering properties to the new object.
To define a creation script you create a script named after the operator type name, either Python (.py) or HScript (.cmd), and place it inside the $HOME/houdiniX.Y/scripts/context/ folder where context is obj, sop, dop, etc. From above, when creating a Geometry object, the script, $HFS/houdini/scripts/obj/geo.cmd is executed.
As with the Geometry object, other operators too maybe have these scripts defined in $HH/scripts/. Overriding these with your own may result in unexpected results. When searching through the HOUDINI_PATH for these scripts Houdini will execute the first matching file it encounters. It will give precedence to a .py file over a .cmd file when they exist in the same directory.
When using Python creation scripts it is recommended to add in a call to source the Hscript script if it exists.
hou.hscript("source geo.cmd")
Python Node Creation Scripts
When writing a node creation script using Python you are given access to the customary kwargs dictionary. This dictionary contains references to the instance of the operator being created.
An example script that sets the color of a 'mynode':
# The new node that is being created. node = kwargs['node'] # Get the node type name as well to ensure we call any hscript script. node_type_name = node.type().name() color = hou.Color((0,0,1)) node.setColor(color) # Be sure to source any .cmd version of the operator create script. hou.hscript("source %s.cmd" % node_type_name)
Notes:
- To disable the running of a script when creating a node, set run_init_scripts=False when calling hou.Node.createNode().
- To force a node to run its creation script, call hou.Node.runInitScripts().



