Advertisement
mrhumbility

Make Null

Jul 27th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.10 KB | None | 0 0
  1. import hou
  2.  
  3.  
  4. def main(nodes=None):
  5.     # First we make sure we are in an approved category by checking
  6.     # against one of the selected nodes
  7.     if not nodes:
  8.         if hou.selectedNodes():
  9.             nodes = hou.selectedNodes()
  10.         else:
  11.             msg = "Please select some nodes"
  12.             exitWithStatusMessage(msg)
  13.     if not isinstance(nodes, (list, tuple)):
  14.         nodes = [nodes]
  15.     curCategory = nodes[0].type().category().name()
  16.  
  17.     approvedCategories = [
  18.         'Sop', 'Driver', 'Vop', 'Cop2', 'Chop', 'Object', 'Dop']
  19.     color = hou.Color([0, 0, 0])
  20.  
  21.     if curCategory in approvedCategories:
  22.         name = "out"
  23.         for aNode in nodes:
  24.             # If we are in the vop category we want to name and place it
  25.             # differently since vops go left to right not top to bottom
  26.             if curCategory == "Vop":
  27.                 name = "n_{0}".format(aNode.name())
  28.                 xPos = aNode.position()[0] + 2
  29.                 yPos = aNode.position()[1]
  30.             else:
  31.                 if curCategory == "Object":
  32.                     name = "null"
  33.                 else:
  34.                     # If the selected node has a unique name, use it for our
  35.                     # new null. If it's a ray, points from volume, or copy node
  36.                     # name the null vis so we can view without the obnoxious
  37.                     # mandatory geo template. If it has a default name just
  38.                     # name it OUT. If the parent node has render in the name,
  39.                     # name the null render. If iso is in the name, its
  40.                     # probably a blast node so strip iso and name itn the rest
  41.                     if "render" in aNode.parent().name().lower():
  42.                         name = "Render"
  43.                     elif aNode.type().name() == "serialize":
  44.                         if aNode.parm("operation").eval() == 1:
  45.                             name = aNode.parm("output").evalAsString()
  46.                         else:
  47.                             name = "OUT_{0}".format(aNode.name())
  48.                     elif ("ray" in aNode.type().name() or
  49.                             "copy" in aNode.type().name() or
  50.                             "pointsfromvolume" in aNode.type().name()):
  51.                         name = "vis_{0}".format(aNode.name())
  52.                         color = hou.Color([0.306, 0.306, 0.306])
  53.                     elif aNode.type().name() in aNode.name():
  54.                         name = "OUT"
  55.                     elif 'iso' in aNode.name():
  56.                         name = 'OUT_{0}'.format(
  57.                             "_".join(aNode.name().split("_")[1:]))
  58.                     elif 'object_merge' in aNode.type().name():
  59.                         if 'IN_' in aNode.name():
  60.                             name = aNode.name()[3:]
  61.                     else:
  62.                         name = "OUT_{0}".format(aNode.name())
  63.                 xPos = aNode.position()[0]
  64.                 yPos = aNode.position()[1] - 1
  65.  
  66.             if(aNode.parent().type().name() in
  67.                ["subnet", "sopsolver", "dopnet"]):
  68.                 null = aNode.parent().createNode('output', name)
  69.                 if aNode.parent().type().name() != "dopnet":
  70.                     numoutputs = -1
  71.                     for n in aNode.parent().children():
  72.                         if n.type().name() == "output" and n != null:
  73.                             numoutputs = max(numoutputs,
  74.                                              n.parm('outputidx').eval())
  75.                             print n.path()
  76.                     null.parm('outputidx').set(numoutputs+1)
  77.             else:
  78.                 null = aNode.parent().createNode("null", name)
  79.             null.setPosition(hou.Vector2(xPos, yPos))
  80.  
  81.             # If we are in sops or dops then we can set the display flags
  82.             if curCategory == "Sop" or curCategory == "Dop":
  83.                 null.setDisplayFlag(True)
  84.                 if curCategory == "Sop":
  85.                     null.setRenderFlag(True)
  86.             null.setColor(color)
  87.             null.setCurrent(True, clear_all_selected=True)
  88.             # Now we set the inputs. If something goes wrong though we will
  89.             # just give up and delete the node. This happens if a node with no
  90.             # outputs is in the selection ie. rop node or chopnet
  91.             try:
  92.                 # For all the outputs in a node, go to each. Loop through all
  93.                 # of that nodes inputs until we have found the original node.
  94.                 # We now know the proper index and can set the inputs correctly
  95.                 for outputs in aNode.outputs():
  96.                     i = 0
  97.                     for inputs in outputs.inputs():
  98.                         if inputs is not None:
  99.                             if aNode.name() == inputs.name():
  100.                                 outputs.setInput(i, null)
  101.                             else:
  102.                                 i += 1
  103.                 null.setFirstInput(aNode)
  104.             except:
  105.                 null.destroy()
  106.     return null
  107.  
  108.  
  109. def exitWithStatusMessage(msg):
  110.     hou.ui.setStatusMessage(msg)
  111.     exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement