Jump to content

Switches and loops


Recommended Posts

Hello,

I have a situation where I need to apply the same operations to several discrete pieces of geometry which will later be exported as separate files.  To save myself some network duplication, I thought I might be able to collect all of these pieces into a switch and iterate over them in a for-loop.  I can't figure out how exactly to make this work.  Is there a better way?  (image illustrates what I'm going for)

Thanks for the help!

image.png.fe27170056d1cd3d2a88c43728c6f7f0.png

Link to comment
Share on other sites

the way i did it in the past was to give each piece of geometry a discrete attribute (name, number, etc), collect them in a merge SOP and then run my loop with that attribute.
if you have a lot of inputs, you might want to use python to automate that primwrangle creation

Link to comment
Share on other sites

if you want to process them separately and save as different files anyway, you can just use Wedge SOP and control switch value with $WEDGENUM variable, then have any sops after switch to process your geo and ROP Geometry Output (referenced in wedge driver) that will save your geo with path varying using $WEDGE variable  

https://www.sidefx.com/docs/houdini/nodes/out/wedge.html

Link to comment
Share on other sites

Thank you so much for the help. I tried both of these methods (merge + named primitives and using a wedge) and they both work.  My specific situation called for a different solution, because I needed to force a heightfield erode recalculation and export the resulting maps in each iteration.  To do this, I wrote a little Python in the session module:

def renderTerrain():
    for i in range(0, 13):
        hou.node("obj/Terrain/Controller").parm("shape_index").set(i)
        hou.node("obj/Terrain/heightfield_erode1").parm("resimulate").pressButton()
        hou.node("obj/Terrain/heightfield_output1").parm("execute").pressButton()

Here, the Controller node's shape_index parameter is referenced in the switch.  I could improve this further by replacing the hard-coded loop range with a count fetched from the switch.

EDIT: @Noobini your solution works well too.  Very simple!

Edited by willrmiller
Link to comment
Share on other sites

  • 2 years later...

Depending on what you are doing in the loop.
if the logic is going to be "compilable",

You can also look into the "Invoke" SOP ;)

that is a way of reusing a part of network, with a different input (generating a different output)
but it only works together with a compiled block as a reference.

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