Jump to content

Python: Copy wrangle to multiple geometry nodes


Chadwick87

Recommended Posts

Beginner to python here. I have a big scene with a lot of geometry and in order to render I need to do some camera culling. My setup has 49 geo nodes and I'm trying to add a wrangle to the end of each network inside each geo node.

So far I have defined some stuff and tried to loop over it with no luck:

wrangle = hou.node("/obj/foo/cullWrangle/")
exportNodes = hou.selectedNodes()

for node in exportNodes:
 len(exportNodes.children())

I thought it might be simple to loop over the selected geo nodes, access the child nodes, define the last sop in each geo node, and then something something add wrangle. Can anyone help me out?

Link to comment
Share on other sites

something like this? this is using the bottom most node in each object to connect the wrangle to.
I attached a HIP file, hope this helps.

# find the lowest node in Y 
def lastnode(node):
  c = node.children()
  lastnode=''
  if(len(c)>0):
    lastnode = c[0]
    posy = c[0].position()[0]
    for i in c:
      y = i.position()[0]
      if(y<posy):
        posy=y
        lastnode=i
  return lastnode

selectednodes=hou.selectedNodes()

# wrangle node to copy into each Object node
wrangle = hou.node('/obj/wrangle/attribwrangle1')

for i in selectednodes:
  lastnode_ = lastnode(i)
  copiednodes=hou.copyNodesTo([wrangle],i)
  if len(copiednodes)>0:
    #connect wrangle to last node
    copiednodes[0].setInput(0,lastnode_)
    # set wrangle node position below last node
    pos = lastnode_.position()
    copiednodes[0].setPosition((pos[0],pos[1]-1))
    
    
  
  
  

 

add_wrangle_inside_geo_nodes.hipnc

  • Like 1
Link to comment
Share on other sites

This is my attempt to find the "last descendant", using python recursion. So far it is working for me:

 

def get_last_descendant (node) :
    try :
        last_descendant = node.outputs()[0]
    except :
        last_descendant = node


    if last_descendant == node :
        return node
    else :
        return get_last_descendant(last_descendant)

 

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...