Python snippets

create attribute

Thanks to F1!

geo = hou.pwd().geometry()
new_p = geo.addAttrib(hou.attribType.Point, 'new_p', 0.0)
old_p = geo.findPointAttrib('old_p')

for point in geo.points():
    val = point.attribValue(old_p)
    point.setAttribValue(new_p, val)

### Or do it this way:

geo = hou.pwd().geometry()
new_p = geo.addAttrib(hou.attribType.Point, 'new_p', 0.0)

values = geo.pointFloatAttribValues('old_p')
geo.setPointFloatAttribValues('new_p', values)

 

first keyframe’s time

thanks to Toadstorm!

keyframes = hou.node('/path/to/node').parm('someParameter').keyframes()
min = 999999
for k in keyframes:
    if k.frame() < min:
        min = k.frame()
return min

 

event callback on parm change

thanks to MrScienceOfficer!

node.addEventCallback(hou.nodeEventType.ParmTupleChanged, call_func)

 

all the tabs

thanks to Bonsak!

tabs = hou.ui.paneTabs() # Get all the tabs

for tab in tabs: # Loop over them
    if tab.type() == hou.paneTabType.NetworkEditor: # Test the type
        tab.setPref('showdep','2') # Set

#get
#networkeditor.getPrefs()

pane under cursor

thanks to Varomix!

def getNetworkType():
    # get desktop
    curdesk = hou.ui.curDesktop()
    activepane = curdesk.paneTabUnderCursor()
    return activepane.type()

Bind light’s “Enable” checkbox to the display flag

obj = hou.node(".")
return obj.isDisplayFlagSet()

Reference SOP input from chopnet Geometry

chopnode = hou.node("..")
chopname = chopnode.name()                  # chopnet_smooth
chopnet,task = chopname.split('_')          # chopnet smooth
channelnodepath = "../../channel_" + task   # ../../channel_smooth
channelnode = hou.node(channelnodepath)
inputpath = channelnode.inputs()[0].path()
return inputpath

instances() nodes of type in the scene

thanks to julian johnson!

node_type = hou.objNodeTypeCategory().nodeTypes()['bone']
for x in node_type.instances():
    print x

hou.playbar.setPlaybackRange(self, start, end)

print node.type().name() # file, filecache, delete, solver, dopimport, …
node = hou.pwd()
path = node.path()
objContextNodeName = path.split(‘/)[-2]