Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hou
- def main(nodes=None):
- # First we make sure we are in an approved category by checking
- # against one of the selected nodes
- if not nodes:
- if hou.selectedNodes():
- nodes = hou.selectedNodes()
- else:
- msg = "Please select some nodes"
- exitWithStatusMessage(msg)
- if not isinstance(nodes, (list, tuple)):
- nodes = [nodes]
- curCategory = nodes[0].type().category().name()
- approvedCategories = [
- 'Sop', 'Driver', 'Vop', 'Cop2', 'Chop', 'Object', 'Dop']
- color = hou.Color([0, 0, 0])
- if curCategory in approvedCategories:
- name = "out"
- for aNode in nodes:
- # If we are in the vop category we want to name and place it
- # differently since vops go left to right not top to bottom
- if curCategory == "Vop":
- name = "n_{0}".format(aNode.name())
- xPos = aNode.position()[0] + 2
- yPos = aNode.position()[1]
- else:
- if curCategory == "Object":
- name = "null"
- else:
- # If the selected node has a unique name, use it for our
- # new null. If it's a ray, points from volume, or copy node
- # name the null vis so we can view without the obnoxious
- # mandatory geo template. If it has a default name just
- # name it OUT. If the parent node has render in the name,
- # name the null render. If iso is in the name, its
- # probably a blast node so strip iso and name itn the rest
- if "render" in aNode.parent().name().lower():
- name = "Render"
- elif aNode.type().name() == "serialize":
- if aNode.parm("operation").eval() == 1:
- name = aNode.parm("output").evalAsString()
- else:
- name = "OUT_{0}".format(aNode.name())
- elif ("ray" in aNode.type().name() or
- "copy" in aNode.type().name() or
- "pointsfromvolume" in aNode.type().name()):
- name = "vis_{0}".format(aNode.name())
- color = hou.Color([0.306, 0.306, 0.306])
- elif aNode.type().name() in aNode.name():
- name = "OUT"
- elif 'iso' in aNode.name():
- name = 'OUT_{0}'.format(
- "_".join(aNode.name().split("_")[1:]))
- elif 'object_merge' in aNode.type().name():
- if 'IN_' in aNode.name():
- name = aNode.name()[3:]
- else:
- name = "OUT_{0}".format(aNode.name())
- xPos = aNode.position()[0]
- yPos = aNode.position()[1] - 1
- if(aNode.parent().type().name() in
- ["subnet", "sopsolver", "dopnet"]):
- null = aNode.parent().createNode('output', name)
- if aNode.parent().type().name() != "dopnet":
- numoutputs = -1
- for n in aNode.parent().children():
- if n.type().name() == "output" and n != null:
- numoutputs = max(numoutputs,
- n.parm('outputidx').eval())
- print n.path()
- null.parm('outputidx').set(numoutputs+1)
- else:
- null = aNode.parent().createNode("null", name)
- null.setPosition(hou.Vector2(xPos, yPos))
- # If we are in sops or dops then we can set the display flags
- if curCategory == "Sop" or curCategory == "Dop":
- null.setDisplayFlag(True)
- if curCategory == "Sop":
- null.setRenderFlag(True)
- null.setColor(color)
- null.setCurrent(True, clear_all_selected=True)
- # Now we set the inputs. If something goes wrong though we will
- # just give up and delete the node. This happens if a node with no
- # outputs is in the selection ie. rop node or chopnet
- try:
- # For all the outputs in a node, go to each. Loop through all
- # of that nodes inputs until we have found the original node.
- # We now know the proper index and can set the inputs correctly
- for outputs in aNode.outputs():
- i = 0
- for inputs in outputs.inputs():
- if inputs is not None:
- if aNode.name() == inputs.name():
- outputs.setInput(i, null)
- else:
- i += 1
- null.setFirstInput(aNode)
- except:
- null.destroy()
- return null
- def exitWithStatusMessage(msg):
- hou.ui.setStatusMessage(msg)
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement