willrmiller Posted October 27, 2018 Share Posted October 27, 2018 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! Quote Link to comment Share on other sites More sharing options...
3dome Posted October 27, 2018 Share Posted October 27, 2018 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 Quote Link to comment Share on other sites More sharing options...
Noobini Posted October 27, 2018 Share Posted October 27, 2018 isn't it this simple ? ForSwitch.hiplc Quote Link to comment Share on other sites More sharing options...
anim Posted October 28, 2018 Share Posted October 28, 2018 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 Quote Link to comment Share on other sites More sharing options...
willrmiller Posted October 28, 2018 Author Share Posted October 28, 2018 (edited) 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 October 28, 2018 by willrmiller Quote Link to comment Share on other sites More sharing options...
Radivarig Posted March 2, 2021 Share Posted March 2, 2021 @Noobini in your example you can also use opninputs("../switch1") for Iterations in foreach_end1 to iterate over all switch inputs automatically. Quote Link to comment Share on other sites More sharing options...
acey195 Posted March 4, 2021 Share Posted March 4, 2021 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. 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.