[Code] Python and Houdini Python (3)

Learning Python, so here is jotted-down notes that might be useful, part 3.

LOG 3

* 1 – hou.Node class
hou.node().node() => call a node (inside a node)
hou.selectedNodes() => return nodes that are being selected

n = hou.node(‘….’)
n.children() => return children nodes inside a node
n.allSubChildren() => return all sub nodes
n.parent()
hou.node(‘…’).outputs() => return all outputs of a node, arbitrary
hou.node(‘…’).inputs() => return all inputs of a node, order matters
n.name()
n.setName()
n.path() => return the full path to the node
n.position()
n.setPosition((0,0))
n.move(vector2)
n.destroy()

s.setInput(2, n, 0) , if n is “None”, it will disconnect the input
n.setColor(hou.Color(1,0,0)) => set color requires a color defined in the hou.Color class
n.setGenericFlag(flag, value) => flag must be in instance of hou.nodeFlag [module], value can be either a Bool or 0 and 1
flag => hou.nodeFlag.DisplayComment
n.comment() to show comment
n.setComment(‘……..’) to set comment or n.appendComment(‘…..’) to append to the existing comment

node type name: geo, subnet, dopnet, attribwrangle…
n.type() => return what type the node is as an object
n.type().name() => return type of node in string
hou.node(‘/obj/’).createNode(‘geo’) => create new geo type node in the selected node

* 2 – user data:
n.userDataDict() => show all user data dictionaries
n.userData(‘keyword’) => show user data for the key provided
n.setUserData(‘keyword name’, ‘value’) => set user data like nodeshape, value must be in string
=> user data will be stored in the node even after closing and reopening Houdini
n.cacheUserData() / n.cacheUserDataDict()
=> temporary user data that will be gone after restarting Houdini
n.destroyUserData(‘keyword’)

mycode = n.asCode() => write out the code that created the node
exec mycode => will execute the string as code


* 3 – hou.Parm class:

hou.parm(‘….’) => use when parameter has only 1 value
hou.parmTuple(‘…’) => use when parameter has multiple values like xyz
n.parms() / n.parmTuples() => return a list of all parms / parmTuples of the node

from parameter, you can also grab tuple; and from the tuple you can grab the index
n.parm(‘scale’).tuple()
hou.parmTuple(‘/obj/geo1/t’)[0] => grab tx which is index 0

p = hou.parm(‘……..’)
p.eval() => evaluate the value of the parameter
p.isTimeDependent() => check for time dependency
hou.evalParm(‘/obj/geo1/scale’)
p.unexpandedString() => return the string as it without evaluating, like a string pointing to a location on disk
p.node() => show the node where the parm is located
p.pressbutton()

p.setExpression(expression, language=hou.exprLanguage, Python) => set Expression language of the parameter to Python
p.revertToDefaults()

* 4 – Startup Scripts:

  • HOUDINI_USER_PREF_DIR – where start-up scripts stay
    123.py is run once every time Houdini launches
    456.py is run whenever a hip file is opened
  • hou.hipFile module
    import sys module to append script directory to Houdini ‘path’ variable when Houdini starts up
    hou.getenv(‘HH’) => get Houdini OTL (hda) env variable
    Note: some hda can be put at a global location for use at all times, but sometimes hda are limited to certain clients, and that’s where variables come in handy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with WordPress.com
Get started
%d bloggers like this: