Chadwick87 Posted August 11, 2020 Share Posted August 11, 2020 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? Quote Link to comment Share on other sites More sharing options...
bunker Posted August 12, 2020 Share Posted August 12, 2020 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 1 Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted August 13, 2020 Share Posted August 13, 2020 wrangle = hou.node("/obj/foo/cullWrangle/") exportNodes = hou.selectedNodes() for n in exportNodes: disp = n.displayNode() # assuming n is of "geo" type w_copy = wrangle.copyTo(disp) w_copy.setInput(0, disp) w_copy.moveToGoodPosition() 1 Quote Link to comment Share on other sites More sharing options...
ikoon Posted August 13, 2020 Share Posted August 13, 2020 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.