• Houdini Scripts

      Add Overscan to Selected Cameras

      Exposes the overscan parameters on selected cameras

      ''' This script will add overscan to selected cameras '''
      
      sel = hou.selectedNodes()
      
      for node in sel:   
          group = node.parmTemplateGroup()
          folder = hou.FolderParmTemplate('folder', 'Overscan')
          folder.addParmTemplate(hou.IntParmTemplate('vm_overscan', 'Image Overscan', 2))    
          group.append(folder)
          node.setParmTemplateGroup(group)
       

      Add Linked Overscan to Selected Cameras

      Exposes the overscan parameters on selected cameras and adds an expression linking the overscan to ROP res overrides

      #import hou
      ''' This script will add overscan to selected cameras 
          It will also add an expression to link the overscan to the ROP res override
      
          Use: select cameras and then when prompted select a rop to apply camera res
               expression
      
      '''
      
      sel = hou.selectedNodes()
      rop = hou.ui.selectNode()
      roppath = str(rop)
      
      for node in sel:   
      
          group = node.parmTemplateGroup()
          folder = hou.FolderParmTemplate('folder', 'Overscan')
          
          folder.addParmTemplate(hou.IntParmTemplate("oscan", "Ford Overscan", 2))
          folder.addParmTemplate(hou.IntParmTemplate('vm_overscan', 'Image Overscan', 2))
          
          group.append(folder)
          node.setParmTemplateGroup(group)
          
          node.parm('vm_overscanx').setExpression('if (ch("' + roppath + '/override_camerares")==0, ch("oscanx"), ch("oscanx")*ch("' + roppath + '/res_fraction"))')
          node.parm('vm_overscany').setExpression('if (ch("' + roppath + '/override_camerares")==0, ch("oscany"), ch("oscany")*ch("' + roppath + '/res_fraction"))')
          
      

      Centre Pivots

      Sets pivot transforms to $CEX, $CEY, $CEZ on selected nodes

      # Centre pivots
      import hou
      
      sel = hou.selectedNodes()
      for nodes in sel:
          nodes.parm('px').setExpression('$CEX')
          nodes.parm('py').setExpression('$CEY')
          nodes.parm('pz').setExpression('$CEZ')
      

      Find/Replace Parameter Expression

      Will find/replace strings within selected nodes’ parameters’ expressions

      import hou
      
      sel = hou.selectedNodes()
              
      dialog = hou.ui.readMultiInput('Find/Replace In Expression', input_labels=['Find: ', 'Replace: ',], buttons=("Find/Replace", "Cancel"),
           severity=hou.severityType.ImportantMessage, title='Find/Replace', close_choice=1)
      
      find = dialog[1][0]
      replace = dialog[1][1]
      
      
      if dialog[0] == 0:
          for n in sel:
              for parms in n.parms():
                  try:
                      newString = str(parms.eval()).replace(find, replace)
                      parms.set(newString)
                  except:
                      print ''
                  try:
                      newExpression = str(parms.expression()).replace(find, replace)
                      parms.setExpression(newExpression)
                  except:
                      print ''
              

      Match Parameters

      Select two nodes and this script will copy all parameters from the first selected node to the second selected

      # --- This tool will match all parameters from the first selected node to the second.
      # --- good for copying ramps as well as the regular stuff.
      
      def matchParams():
          import hou
      
          value = 0
          sel = hou.selectedNodes()
      
          if len(sel) == 2:
              source = sel[0]
              dest = sel[1]
              for param in source.parms():
                  sourceParm = param.name()  # source parameter
                  destParm = dest.parm(sourceParm)  # Destination parameter
                  try:
                      destParm.deleteAllKeyframes()
                  except:
                      value += 1
                  try:
                      sourceLanguage = param.expressionLanguage()
                      destParm.setExpression(param.expression(), language=sourceLanguage)
      
                  except:
                      value += 1
                  try:
                      destParm.set(param.eval())
                  except:
                      value += 1
                  try:
                      destParm.set(param.unexpandedString())
                  except:
                      value += 1
      
                  if param.isLocked() == 'True':
                      destParm.lock(on)
          else:
              print 'Select two nodes to match parameters'
      
      matchParams()

      Toggle Update Mode

      This script will toggle between Manual and Auto Update modes

      if hou.ui.updateMode() == hou.updateMode.AutoUpdate:
          hou.ui.setUpdateMode(hou.updateMode.Manual)
      else:
          hou.ui.setUpdateMode(hou.updateMode.AutoUpdate)

      Set Camera Parameters

      A short example to set all camera parameters – specifically resolution and icon scale

      import hou
      ''' This script will set all cameras res to those determined below
          and icon scale'''
      
      resx = "1920"
      resy = "1080"
      iconsize = "100"
      
      cameras = hou.nodeType(hou.objNodeTypeCategory(), "cam")
      cameras.instances()
      
      for cams in cameras.instances():
          cams.parm("resx").set(resx)
          cams.parm("resy").set(resy)
          cams.parm("iconscale").set(iconsize)

      Split Into Groups

      This script will break out all the groups within the geo from the selected node using blasts

      import hou
      
      selectedNodes = hou.selectedNodes()
      
      for n in selectedNodes:
          groups = n.geometry().primGroups()
          for group in groups:
          
              blastNode = n.createOutputNode('blast')
              blastNode.setName(group.name())
              blastNode.parm('group').set(group.name())
              blastNode.parm('negate').set(1) 
              
              outNull = blastNode.createOutputNode('null')
              outNull.setName('OUT_' + group.name())
              
              outNull.setColor(hou.Color([1,0,0]))

      Softimage Scripts

      Move Selected Items to Background Partitions

      This script will move selected items into background partitions of either the current pass or multiple selected passes

      # Move selected objects to background partitions
       
      # created by Gareth Bell
       
      # original created in VBScript 28-11-11
      # converted to Python 26-07-2012
       
       
      # Description:
      # This script will put the selected objects into either the current passes bg partitions or, if selected, multiple passes bg partitions
       
      ##################################
       
      # To use:  select objects and passes. Run.
       
      ##################################
       
      import win32com
      xsi = Application
       
      #create collections to store objects
      geoColl = win32com.client.Dispatch( "XSI.Collection" )
      passesColl = win32com.client.Dispatch( "XSI.Collection" )
      lightsColl = win32com.client.Dispatch( "XSI.Collection" )
       
      selection = win32com.client.Dispatch( "XSI.Collection" )
      selection.AddItems (xsi.Selection)
       
      #sort selection into collections (objects, lights and passes)
      for obj in selection:
                if obj.type == "light":
                         lightsColl.AddItems (obj)
                elif obj.type == "Pass":
                         passesColl.AddItems (obj)
                else:
                         geoColl.AddItems (obj)
                        
      passCount = passesColl.Count
       
      #decide if sorting is in only the current pass or multiple passes
      if passCount > 0:
                for eachPass in passesColl:     
      			print str(geoColl) + " has/have been put into the background partition in " + str(eachPass.name)
      			xsi.MoveToPartition(str(eachPass) + ".background_objects_partition", geoColl, eachPass)
      			print str(lightsColl) + " has/have been put into the background partition in " + str(eachPass.name)
      			xsi.MoveToPartition(str(eachPass) + ".background_lights_partition", lightsColl, eachPass)
      else:
      	currentPass = xsi.ActiveProject.ActiveScene.ActivePass
      	print str(geoColl) + " has/have been put into the background partition in the current pass"
      	xsi.MoveToPartition(str(currentPass) + ".background_objects_partition", geoColl, currentPass)               
      	print str(lightsColl) + " has/have been put into the background partition in the current pass"
      	xsi.MoveToPartition(str(currentPass) + ".background_lights_partition", lightsColl, currentPass)    
      				   
      				   

      Convert Models to Nulls

      This small script will convert selected models into nulls.

      import win32com
      xsi = Application
       
      objs = win32com.client.Dispatch( "XSI.Collection" )
      objs.AddItems (xsi.Selection)
       
       
      for i in objs:
                if i.Type == "#model":
                         newNull = xsi.GetPrim("null", str(i) + "_null", "", "")   #create null
                         xsi.MatchTransform(newNull, i, "siSRT")   #match it's transforms to the model
                        
                         for eachChild in i.Children:  #parent model's children to null
                                   xsi.ParentObj(newNull, eachChild)
                                  
                         try:
                                   for eachGroup in i.Groups:   #move groups to nulls parent
                                            xsi.CopyPaste (eachGroup,"", newNull.Parent, 1)
                         except:
                                   print ""
       
                         try:
                                   xsi.ParentObj (i.Parent, newNull)    #parent new null to original models parent
                         except:
                                   print ""
       
       
                         xsi.DeleteObj (i)    #Delete original model
               
                else:
                         print "Select models only"

      mia2vray Material Conversion

      This small script will swap selected materials mia shaders into vraymtrl shaders. This script was inspired by Paul Driesen’s script for Maya 

      #mia2vray converter
      #author: gareth bell
      #date: 15-10-2012
      
      #This script will break the back of converting mia shaders in selected materials into vrayMtls
      
      #Use: Select materials. Run
      
      import win32com.client
      import siutils
      
      from siutils import si
      from siutils import C
      
      xsi = Application
      coll = win32com.client.Dispatch( "XSI.Collection" )
      vrayMaterials = win32com.client.Dispatch( "XSI.Collection" )
      
      
      #############################################
      def traverse( s, coll ):
          for p in s.Parameters:
              if p.Source and p.Source.IsClassOf( C.siShaderParameterID ):
                  coll.Add( p.Source.Parent )
                  traverse( p.Source.Parent, coll )
      
          for l in s.TextureLayers:
              for y in l.Parameters:
                  if y.Source and y.Source.IsClassOf( C.siShaderParameterID ):
                      coll.Add( y.Source.Parent ) 
                      traverse( y.Source.Parent, coll )
      		  
      ############################################
      
      def createVrayShader (eachShader):
      			vrayMaterial = xsi.CreateShaderFromProgID("Softimage.VRayMtl.1.0", mat, "VRayMtl")
      			vrayMaterials.AddItems (vrayMaterial) 
      			miaName = eachShader.name
      			vrayName = vrayMaterial.FullName
      			
      			#match diffuse colour
      			xsi.SetValue( (str(vrayName) + ".diffuse_color.red"), eachShader.diffuse.red.value, "")
      			xsi.SetValue( (str(vrayName) + ".diffuse_color.green"), eachShader.diffuse.green.value, "")
      			xsi.SetValue( (str(vrayName) + ".diffuse_color.blue"), eachShader.diffuse.blue.value, "")
      			
      			#match reflection colour
      			xsi.SetValue( (str(vrayName) + ".reflection_color.red"), eachShader.refl_color.red.value, "")
      			xsi.SetValue( (str(vrayName) + ".reflection_color.green"), eachShader.refl_color.green.value, "")
      			xsi.SetValue( (str(vrayName) + ".reflection_color.blue"), eachShader.refl_color.blue.value, "")
      			
      			#match refraction colour
      			xsi.SetValue( (str(vrayName) + ".refr_color.red"), eachShader.refr_color.red.value, "")
      			xsi.SetValue( (str(vrayName) + ".refr_color.green"), eachShader.refr_color.green.value, "")
      			xsi.SetValue( (str(vrayName) + ".refr_color.blue"), eachShader.refr_color.blue.value, "")
      			
      			#match roughness
      			xsi.SetValue( (str(vrayName) + ".roughness"), eachShader.diffuse_roughness.value, "")
      			
      			#match gloss
      			xsi.SetValue( (str(vrayName) + ".refr_glossiness"), eachShader.refr_gloss.value, "")
      			
      			#match IOR
      			xsi.SetValue( (str(vrayName) + ".refr_ior"), eachShader.refr_ior.value, "")
      			
      			#match anisotropy
      			a = eachShader.anisotropy.value
      			#equation for getting anisotropy values in range 0 to 10 (mia_shader) converted to -1 to 1 (vray_shader) is (a/5.0)-1)
      			xsi.SetValue( (str(vrayName) + ".brdf_anisotropy"), (a/5.0)-1.0)
      			
      			#match rotation
      			xsi.SetValue( (str(vrayName) + ".brdf_rotation"), eachShader.anisotropy_rotation.value, "")
      			
      			#match fresnel
      			fres = eachShader.brdf_fresnel.value
      			if fres == True:
      				xsi.SetValue( (str(vrayName) + ".reflection_enable_fresnel"), False, "")
      			else:
      				xsi.SetValue( (str(vrayName) + ".reflection_enable_fresnel"), True, "")
      			
      			inputCnx = win32com.client.Dispatch( "XSI.Collection" )
      			cnxPoint = win32com.client.Dispatch( "XSI.Collection" )
      			
      			for p in eachShader.Parameters:
      				if p.Source and p.Source.IsClassOf( C.siShaderParameterID ):
      					inputCnx.Add (p.Source.Parent)
      					cnxPoint.Add (p)
      
      			for i in range (0, inputCnx.Count):
      				#print inputCnx(i)
      				#print cnxPoint(i).Name
      				
      				if cnxPoint(i).Name == "diffuse":
      					vrayCnxPoint = "diffuse_color"
      				elif cnxPoint(i).Name == "refl_color":
      					vrayCnxPoint = "reflection_color"
      				elif cnxPoint(i).Name == "refr_color":
      					vrayCnxPoint == "refr_color"
      				elif cnxPoint(i).Name == "roughness":
      					vrayCnxPoint == "diffuse_roughness"
      				elif cnxPoint(i).Name == "refr_glossiness":
      					vrayCnxPoint == "refr_gloss"
      				elif cnxPoint(i).Name == "refr_ior":
      					vrayCnxPoint == "refr_ior"
      				elif cnxPoint(i).Name == "anisotropy":
      					vrayCnxPoint == "brdf_anisotropy"
      				elif cnxPoint(i).Name == "brdf_rotation":
      					vrayCnxPoint == "anisotropy_rotation"
      				
      				xsi.SIConnectShaderToCnxPoint( (inputCnx(i).out) , str(vrayName) + "." + str(vrayCnxPoint))
      				
      			#match name to mia_name
      			xsi.SetValue((str(vrayName) + ".Name"), "VRay" + str(eachShader.name)[3:])
      
      
      #############################################################
      #############################################################
      
      
      prefs = xsi.Preferences
      #get commandlog prefs
      origPrefs = prefs.GetPreferenceValue ("scripting.cmdlog")
      #turn log off
      prefs.SetPreferenceValue ("scripting.cmdlog", False)
      
      # get material
      for mat in xsi.Selection:
      	traverse( mat, coll )
      	coll.Unique = True
      	
      	for eachShader in coll:
      		if "Softimage.mia_material_phen.1.0" in eachShader.ProgID:
      			print ""          
      		elif "mentalray.mia_material_x.1.0" in eachShader.ProgID:
      			print ""
      		else:
      			coll.Remove( eachShader )
      
      	for eachShader in coll:
      		createVrayShader (eachShader)
      	#get mia shaders output connections and plug them into the newly created vRay shader
      	for s in range (0, coll.count):
      		targets = coll(s).GetShaderParameterTargets("")	
      		for eachTarget in targets:
      			xsi.SIConnectShaderToCnxPoint(str(vrayMaterials(s)) + ".out" , eachTarget, False)
      			
      		#delete mia shader
      		xsi.DeleteObj (coll(s))
      		
      	#empty collections
      	vrayMaterials.RemoveAll()
      	coll.RemoveAll()
      		
      #restore original log prefs	
      prefs.SetPreferenceValue ("scripting.cmdlog", origPrefs)
      

      Extrude Along Multiple Curves

      It came to my attention from a colleague today that there isn’t an easy way to extrude along multiple curves in Softimage. So I knocked up this little script for her.

      #extrudeMultiCurves_001
      
      #To Use: 
      # 1) Select the curves you want to extrude along.
      # 2) Run script
      # 3) Pick the profile curve
      
      
      import win32com
      xsi = Application
      
      #collect all curves
      extCurves = win32com.client.Dispatch( "XSI.Collection" )
      extCurves.AddItems (xsi.Selection)
      
      #pick profile curve
      profileCurve = xsi.PickElement ("", "Pick Profile Curve")
      
      #loop through all extCurves and extrude along profileCurve
      for i in range (0, extCurves.count):
      	xsi.ApplyGenOp("Extrusion", "MeshSurface", str(profileCurve(2)) + ";" + str(extCurves(i)), 3, "siPersistentOperation", "siKeepGenOpInputs", "")

      Delete Empty Partitions

      I like to keep my passes tidy so this little script just strips out any empty partitions on selected passes.

      #  USE: Select passes and run the script
      
      import win32com
      
      xsi = Application
      
      selectedPasses = win32com.client.Dispatch( "XSI.Collection" )
      selectedPasses.AddItems (xsi.Selection)
      
      #--------------------------------------------------------------
      #--------------------------------------------------------------
      #--------------------------------------------------------------
      
      def stripPass(eachPass):
      	partitionsColl = win32com.client.Dispatch( "XSI.Collection" )
      	for eachPartition in eachPass.Partitions:
      		partitionsColl.AddItems (eachPartition)
      	
             #-- Remove background partitions from the collection ---------------------
      	partitionsColl.RemoveItems (partitionsColl[0])
      	partitionsColl.RemoveItems (partitionsColl[0])
      	
      	for eachPartition in partitionsColl:
      		if eachPartition.Members.Count == 0:
      			print str(eachPartition) + " is empty :: Deleted ::"
      			xsi.DeleteObj (eachPartition)
      
      #--------------------------------------------------------------
      #--------------------------------------------------------------
      
      
      for eachPass in selectedPasses:
      	stripPass(eachPass)
      	

      Nuke Scripts

      Multi Paster

      A simple snippet to paste multiples of the copied node underneath the selected nodes.
      To use just copy the node you want (ctrl-c). Select the nodes on which you want to paste the copies and run the script. Simples!

      #paste to multiple selection
      selected = nuke.selectedNodes()
      
      for eachNode in selected:
          n = nuke.toNode(str(eachNode.name()))
          n.knob("selected").setValue(True)
          nuke.nodePaste("%clipboard%")