Python
Delayed Load Setup
Just click the node(s) which has the path to your caches (works with Rop output, Geometry, file and file cache nodes) and click the tool. Voila! It creates a delayed load for the caches.#function for node variable: return type, description and namedef extract_getTypeName(node): nodetype = node.type() description = nodetype.description() type_name = nodetype.name() return type_name #show selection tuple namesselection = hou.selectedNodes()print len(selection)my_list = ""if len(selection) < 1 : my_list = "nothing selected, please select at least one object"else: a=1 for sel in selection: my_list = "selected object : " + sel.name() a=a+1 hou.ui.displayMessage(my_list, buttons=('OK',))
#for each object in selectionlenght = len(selection)print "DONE!"for i in range(lenght):
#create python variable for selected node selected = hou.selectedNodes()[i] if selected: meshop=hou.node('/shop'); meshop=meshop.createNode('vm_geo_file'); meshop.setName('delayed_load_shop_1', 1) targetdshop=meshop.path(); meobj=hou.node('/obj') meobj=meobj.createNode("geo"); meobj.setParms({"shop_geometrypath":targetdshop}); meobj.setName('DELAYED_load_geo_1', 1) targetfile=selected.parm('file') or selected.parm('sopoutput') mefile=meobj.node('file1') meobj.parm("geo_velocityblur").set(1) meobj.parm("vm_forcegeometry").set(0) meshop.parm("file").set(targetfile)
#for each object in selectionlenght = len(selection)print "DONE!"for i in range(lenght):
#create python variable for selected node selected = hou.selectedNodes()[i] if selected: meshop=hou.node('/shop'); meshop=meshop.createNode('vm_geo_file'); meshop.setName('delayed_load_shop_1', 1) targetdshop=meshop.path(); meobj=hou.node('/obj') meobj=meobj.createNode("geo"); meobj.setParms({"shop_geometrypath":targetdshop}); meobj.setName('DELAYED_load_geo_1', 1) targetfile=selected.parm('file') or selected.parm('sopoutput') mefile=meobj.node('file1') meobj.parm("geo_velocityblur").set(1) meobj.parm("vm_forcegeometry").set(0) meshop.parm("file").set(targetfile)
Save (backup) .hip files with comments
click the shelf tool and type a comment. A version of hip file will be saved with your comment, whilst you'll be working on the same file.import os.path as opimport hou
activeSession = hou.hipFile.name()
# Fetch tuple with index of pressed button and input text.choice, text = hou.ui.readInput('Type comments message', help='Type comments description.', title='Commented HIP', buttons=('OK', 'Cancel'), default_choice=1, close_choice=1)
# If OK was pressed with some non-empty text.if choice == 0 and text: path = hou.hipFile.path() dir, name = op.split(path)
# Discard extension. name = op.splitext(name)[0]
# Discard one '.anytext' occurence at the end. name = name.rsplit('.', 1)[0]
# Make new name with input text. new_name = '%s.%s.hip' % (name, text)
# Finally, create an absolute path to save file to. new = op.normpath(op.join(dir, new_name))
# Save the file. hou.hipFile.save(file_name=new, save_to_recent_files=False) hou.hipFile.setName(path) print "File saved to - " + (new)
activeSession = hou.hipFile.name()
# Fetch tuple with index of pressed button and input text.choice, text = hou.ui.readInput('Type comments message', help='Type comments description.', title='Commented HIP', buttons=('OK', 'Cancel'), default_choice=1, close_choice=1)
# If OK was pressed with some non-empty text.if choice == 0 and text: path = hou.hipFile.path() dir, name = op.split(path)
# Discard extension. name = op.splitext(name)[0]
# Discard one '.anytext' occurence at the end. name = name.rsplit('.', 1)[0]
# Make new name with input text. new_name = '%s.%s.hip' % (name, text)
# Finally, create an absolute path to save file to. new = op.normpath(op.join(dir, new_name))
# Save the file. hou.hipFile.save(file_name=new, save_to_recent_files=False) hou.hipFile.setName(path) print "File saved to - " + (new)
Set houdini variables for paths
Use this tool to set variables for current shot. ($RENDER, $CACHE and $IFD )message=hou.ui.displayMessage("Note: This is a one time scene setup tool to be used only during a fresh start of your shot.", buttons=("Continue", "Cancel"))if message ==1: hou.ui.displayMessage("Cancelled", buttons=('OK',))
if message ==0:
#Set render path hou.ui.displayMessage("Please Select a directory for your renders") job=hou.hscriptExpression('$JOB') renderDir = hou.ui.selectFile(start_directory = job, title = "Select render path", collapse_sequences = False, file_type = hou.fileType.Directory, multiple_select = False, chooser_mode = hou.fileChooserMode.Read) if renderDir == "": print "RENDER path: Not set / Unchanged " if renderDir != "": hou.hscript("setenv RENDER = '%s'" % renderDir) print "RENDER path: " + renderDir
#Set cache path hou.ui.displayMessage("Now select a directory for your caches") job=hou.hscriptExpression('$JOB') cacheDir = hou.ui.selectFile(start_directory = job, title = "Select cache path", collapse_sequences = False, file_type = hou.fileType.Directory, multiple_select = False, chooser_mode = hou.fileChooserMode.Read) if cacheDir == "": print "CACHE path: Not set / Unchanged " if cacheDir != "": hou.hscript("setenv CACHE = '%s'" % cacheDir) print "CACHE path: " + cacheDir
#Set ifds path hou.ui.displayMessage("And finally select a directory for your IFDs") job=hou.hscriptExpression('$JOB') ifdDir = hou.ui.selectFile(start_directory = job, title = "Select IFDs path", collapse_sequences = False, file_type = hou.fileType.Directory, multiple_select = False, chooser_mode = hou.fileChooserMode.Read) if ifdDir == "": print "IFD path: Not set / Unchanged " if ifdDir != "": hou.hscript("setenv IFD = '%s'" % ifdDir) print "IFDs path: " + ifdDir hou.ui.displayMessage("Setup complete", buttons=('OK',))
if message ==0:
#Set render path hou.ui.displayMessage("Please Select a directory for your renders") job=hou.hscriptExpression('$JOB') renderDir = hou.ui.selectFile(start_directory = job, title = "Select render path", collapse_sequences = False, file_type = hou.fileType.Directory, multiple_select = False, chooser_mode = hou.fileChooserMode.Read) if renderDir == "": print "RENDER path: Not set / Unchanged " if renderDir != "": hou.hscript("setenv RENDER = '%s'" % renderDir) print "RENDER path: " + renderDir
#Set cache path hou.ui.displayMessage("Now select a directory for your caches") job=hou.hscriptExpression('$JOB') cacheDir = hou.ui.selectFile(start_directory = job, title = "Select cache path", collapse_sequences = False, file_type = hou.fileType.Directory, multiple_select = False, chooser_mode = hou.fileChooserMode.Read) if cacheDir == "": print "CACHE path: Not set / Unchanged " if cacheDir != "": hou.hscript("setenv CACHE = '%s'" % cacheDir) print "CACHE path: " + cacheDir
#Set ifds path hou.ui.displayMessage("And finally select a directory for your IFDs") job=hou.hscriptExpression('$JOB') ifdDir = hou.ui.selectFile(start_directory = job, title = "Select IFDs path", collapse_sequences = False, file_type = hou.fileType.Directory, multiple_select = False, chooser_mode = hou.fileChooserMode.Read) if ifdDir == "": print "IFD path: Not set / Unchanged " if ifdDir != "": hou.hscript("setenv IFD = '%s'" % ifdDir) print "IFDs path: " + ifdDir hou.ui.displayMessage("Setup complete", buttons=('OK',))
Make Null node by pressing a key
You can use this code for any nodes you want by just slightly modifying it. Just don't forget to set a shortcut key from the Hotkeys tab..selected_nodes = hou.selectedNodes()for node in selected_nodes: parent = node.parent() name_node_selected = node.name() null = parent.createNode('null','OUT_' + name_node_selected) null.setInput(0,node) macolo = hou.Color((0,0.5,0)) null.setColor(macolo) pos = node.position() null.setPosition(pos) null.move([0,-1]) #flags null.setSelected(True,True) null.setDisplayFlag(True) null.setRenderFlag(True)
Object merge a selected node by pressing a key
Don't forget to set a shortcut key from the Hotkeys tab..#definedef objmerge(): #pick node network_pane = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor) parmeters = hou.ui.paneTabOfType(hou.paneTabType.Parm) pos = network_pane.selectPosition() if(len(hou.selectedNodes()) > 0): sel = hou.selectedNodes()[0] node = network_pane.pwd().createNode("object_merge", "merge_"+sel.name()) node.parm('objpath1').set(sel.path()) else: node = network_pane.pwd().createNode("object_merge") #arrange node.setPosition(pos) network_pane.setCurrentNode(node) node.setSelected(True, clear_all_selected=1) #color mycolor = hou.Color((0,0.5,0)) node.setColor(mycolor) #flags node.setSelected(True,True) node.setDisplayFlag(True) node.setRenderFlag(True) #callback objmerge()
Change BG color of viewport by pressing a key
Again....don't forget to set shortcut key.import toolutils
bg = None
try: # cycle next bg if kwargs['ctrlclick']: raise bgs = hou.session.bg[:] bgs = bgs[1:]+bgs[:1] if kwargs['shiftclick']: bgs = ['bw', 'light', 'wb'] bg = bgs[0] hou.session.bg = bgsexcept: # set up default bg vars hou.session.bg = ['wb', 'bw', 'light'] bg = hou.session.bg[0]
bgs = { 'wb':'dark', 'bw':'grey', 'light':'light' }
hou.hscript("viewdisplay -B %s *" % bg)hou.ui.setStatusMessage("Cycled background to %s" % bgs[bg].upper() )
bg = None
try: # cycle next bg if kwargs['ctrlclick']: raise bgs = hou.session.bg[:] bgs = bgs[1:]+bgs[:1] if kwargs['shiftclick']: bgs = ['bw', 'light', 'wb'] bg = bgs[0] hou.session.bg = bgsexcept: # set up default bg vars hou.session.bg = ['wb', 'bw', 'light'] bg = hou.session.bg[0]
bgs = { 'wb':'dark', 'bw':'grey', 'light':'light' }
hou.hscript("viewdisplay -B %s *" % bg)hou.ui.setStatusMessage("Cycled background to %s" % bgs[bg].upper() )
Merge multiple VDBs
select all the VDB nodes and click the tool of merge them by steps.selected_nodes = hou.selectedNodes()vdbcombines = []
for x, node in enumerate(selected_nodes): if x < len(selected_nodes)-1: vdbcombine = node.createOutputNode('vdbcombine') vdbcombine.setNextInput(selected_nodes[x+1]) vdbcombine.setParms({'operation':'add'}) vdbcombines.append(vdbcombine)
for x, vdbcombine in enumerate(vdbcombines): if x < len(vdbcombines)-1: vdbcombine.setInput(1, vdbcombines[x+1])
for x, node in enumerate(selected_nodes): if x < len(selected_nodes)-1: vdbcombine = node.createOutputNode('vdbcombine') vdbcombine.setNextInput(selected_nodes[x+1]) vdbcombine.setParms({'operation':'add'}) vdbcombines.append(vdbcombine)
for x, vdbcombine in enumerate(vdbcombines): if x < len(vdbcombines)-1: vdbcombine.setInput(1, vdbcombines[x+1])
Add nodes to Force objects (Mantra)
Select nodes and click the shelf tool to add them to force objects in mantra. The code can be modified to add nodes to any parameter in Mantra...import houselection = hou.selectedNodes()names = [n.name() for n in selection]my_list = ""if len(selection) < 1 :my_list = "nothing selected, please select at least one object"else:a=1for sel in selection:my_list = my_list + "\n" + "selected object " + str(a) + ":" + sel.name()a=a+1 hou.ui.displayMessage(my_list, buttons=('OK',))length = len(selection)print "Number of nodes selected: " + str(length)paths = [n.path() for n in hou.node('/out').allSubChildren()if n.type() == hou.nodeType('Driver/ifd')]selected = hou.ui.selectFromTree(choices=paths)mantras = [hou.node(path) for path in selected]for m in mantras:m.parm('forceobject').set(' '.join(n.name() for n in hou.selectedNodes())) # CHANGE PARAMETER NAME AS REQURIEDm.parm('vobject').set("")print ("Selected mantra nodes : ") + m.name()new_name=' '.join(names)hou.ui.displayMessage("( "+ (new_name) + " ) - added to selected mantra(s) matte objects.", buttons=('*Claps*',))
Save scene faster on a network
This tool saves your scene a bit faster when you're on a network drive. Helps if you're experiencing slow saving times even on a fast network.
activeSession = hou.hipFile.name()hou.hscript("setenv HOUDINI_BUFFEREDSAVE = 1")hou.hscript("setenv HOUDINI_DISABLE_SAVE_THUMB = 1")hou.hipFile.save()hou.ui.setStatusMessage("Scene saved " + activeSession)