Jump to content

pyro shelf tools to SOPs


bunker

Recommended Posts

Houdini's pyro shelf tools create 3 nodes on /obj/ level. I really hate that and got tired of copy+paste+renaming nodes...
I wrote a simple shelf tool python script to fix that. It works for PyoFX and Sparse PyoFX shelf tools.
hope someone finds it useful :lol: and if anyone can improve that script or make it more generic, please post it here...

sparsepyroshelf.png.21e8f0b5f55756bda46dbb5ffc8feaa4.png

import re

# move dopnet to SOPs
def dopnet2sop():
  # find first dopnet (assuming there's only one)
  # replace relative external paths to absolute paths
  dopnet=hou.nodeType("Object/dopnet").instances()[0]

  sourceNode=''
  for dopnode in dopnet.children():
    for parm in dopnode.parms():
      nodepath=parm.evalAsNode()
      if nodepath!=None and len(nodepath.path().split(dopnet.path()))==1:
          # convert to absolute path
          path = parm.evalAsNode().path()
          parm.set(path)
          # find the pyro source's path
          if dopnode.type().name()=='volumesource':
            sourceNode=hou.node(path)

  sopDopnet = sourceNode.parent().createNode("dopnet")
  pos = sourceNode.position()
  sopDopnet.setPosition((pos[0],pos[1]-1))
  
  hou.copyNodesTo(dopnet.children(),sopDopnet)
  dopnet.destroy()
  return sopDopnet

# set dopnet as reference in dopnode's path
def fixdopio(dopnet):
  di=None
  for dopio in hou.nodeType("Sop/dopio").instances():
    dp=dopio.evalParm("doppath")
    dn=dopio.evalParm("dopnode")
    r = '`chsop("doppath")`'
    a = re.sub(dp,r,dn)    
    dopio.parm("dopnode").set(a)
    dopio.parm("doppath").set(dopnet.path())
    di=dopio
  return di    

# move import nodes to SOPs
def moveDopioNodes(sopDopnet,dopio):
  dopIoParent=dopio.parent()

  # find highest node on y axis
  x=0
  y=0
  for i in dopIoParent.children():
    pos=i.position()
    x=min(x,pos[0])
    y=max(y,pos[1])

  ioNodes=hou.copyNodesTo(dopIoParent.children(),sopDopnet.parent())

  diffx=x-sopDopnet.position()[0]
  diffy=y-sopDopnet.position()[1]
  for ioNode in ioNodes:
    pos = ioNode.position()
    ioNode.setPosition((pos[0]-diffx,pos[1]-diffy-1))
  dopIoParent.destroy()

# remove unused Output dop nodes
def removeUnusedOutputnodes():
  for out in hou.nodeType("Dop/output").instances():
    if len(out.inputs())==0:
      out.destroy()
  
# move dopnet and dopio to SOPs
hou.setUpdateMode(hou.updateMode.Manual)
sopDopnet=dopnet2sop()
dopio=fixdopio(sopDopnet)
moveDopioNodes(sopDopnet,dopio)
removeUnusedOutputnodes()
hou.setUpdateMode(hou.updateMode.OnMouseUp)
Edited by bunker
  • Like 3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...