Lake House - for loop
17434 19 7-
- maxeneg
- Member
- 1 posts
- Joined: Oct. 2017
- Offline
-
- neil_math_comp
- Member
- 1743 posts
- Joined: March 2012
- Offline
You can use the For Loop blocks. Depending on what sort of thing you're doing, there's “For-Each Connected Piece”, “For-Each Named Primitive”, “For-Each Number”, “For-Each Point”, “For-Each Primitive”, and “For-Loop with Feedback”. They set up a block to put operations in that acts similarly to the subnetwork, but all at the same network level, so that you don't have to keep diving in and out of the subnet. They also don't rely on stamping, so it's much easier to set up nested loops correctly.
There are a few examples around the forum showing various ways to use them; I don't know exactly which ones to point you to, since I don't know the specific scenario, but searching for
There are a few examples around the forum showing various ways to use them; I don't know exactly which ones to point you to, since I don't know the specific scenario, but searching for
for loop example
should hopefully find some. ![](/static/djangobb_forum/img/smilies/smile.png)
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
-
- Airlawn
- Member
- 9 posts
- Joined: Dec. 2013
- Offline
I'm still a little confused on the new for each loop myself so I might be doing something wrong but will try and help and maybe better understand it myself by writing it here.
For that tutorial create a for each loop with the end block as iteration method "By Count“ and you are using ”Feedback Each Iteration“ Merge Each Iteration is like the old merge results checkbox.
Set the Block Begin Method to ”Fetch Feedback" and click the Create Meta Import Node. This Meta Input node is how you know which iteration you are in, in the for each loop and I will rename the node "nodename“ just to write something I can refer to later. The Metainput node is just a block begin with the Method set to ”Fetch Metadata" but clicking the button sets up the Block Path for you.
Plug the attribute create which in the tutorial should be labeled box_id into the “Block Begin”.
In the old tutorial you would often be using the stamp function with the for each loop now you are using that meta input node. Call the meta input node and the iteration the loop is in by writing detail(“../nodename”,“iteration”,0)
So in the old tutorial you would be calling the box id value stamp(“..”, “FORVALUE_stackboxes”, 0)+1 the new thing would be detail(“../nodename”,iteration",0)+1.
The locate node "@box_id==`stamp(“..”, “FORVALUE_stackboxes”, 0)`“
would now be ”@box_id==`detail(“../nodename”,“iteration”,0)`" etc.
![](/forum/attachment/c66f370718cc70ce967e549daad50dd134acfd5d/)
I hope that works enough to let you continue.
There are some other gotchas in newer Houdini and the move away from the stamp function. I think once anyone me included gets it, it will be a more direct, faster and easy to use method. For now it still trips me up if I am following something and I have to try and create it the old way look at it as I create it the new way.
For that tutorial create a for each loop with the end block as iteration method "By Count“ and you are using ”Feedback Each Iteration“ Merge Each Iteration is like the old merge results checkbox.
Set the Block Begin Method to ”Fetch Feedback" and click the Create Meta Import Node. This Meta Input node is how you know which iteration you are in, in the for each loop and I will rename the node "nodename“ just to write something I can refer to later. The Metainput node is just a block begin with the Method set to ”Fetch Metadata" but clicking the button sets up the Block Path for you.
Plug the attribute create which in the tutorial should be labeled box_id into the “Block Begin”.
In the old tutorial you would often be using the stamp function with the for each loop now you are using that meta input node. Call the meta input node and the iteration the loop is in by writing detail(“../nodename”,“iteration”,0)
So in the old tutorial you would be calling the box id value stamp(“..”, “FORVALUE_stackboxes”, 0)+1 the new thing would be detail(“../nodename”,iteration",0)+1.
The locate node "@box_id==`stamp(“..”, “FORVALUE_stackboxes”, 0)`“
would now be ”@box_id==`detail(“../nodename”,“iteration”,0)`" etc.
I hope that works enough to let you continue.
There are some other gotchas in newer Houdini and the move away from the stamp function. I think once anyone me included gets it, it will be a more direct, faster and easy to use method. For now it still trips me up if I am following something and I have to try and create it the old way look at it as I create it the new way.
Edited by Airlawn - Jan. 12, 2018 04:36:45
-
- SailorTwift
- Member
- 2 posts
- Joined: Dec. 2016
- Offline
@Airlawn
Hello. I tried to do it your way and everything seems to work except one thing. Once I paste detail(“../nodename”,“iteration”,0) in the Seed value I get error in the origin box's Size parameter. That's what you put in the Seed value, right? Or I misunderstood?
(Error says “Unable to evaluate expression - Syntax error”, and it only happens when I change the Seed value)
Hello. I tried to do it your way and everything seems to work except one thing. Once I paste detail(“../nodename”,“iteration”,0) in the Seed value I get error in the origin box's Size parameter. That's what you put in the Seed value, right? Or I misunderstood?
(Error says “Unable to evaluate expression - Syntax error”, and it only happens when I change the Seed value)
-
- PlayingKarrde
- Member
- 1 posts
- Joined: Jan. 2018
- Offline
SailorTwiftI was getting this error too and I think it came from copy/pasting. I wrote it out myself and it worked
@Airlawn
Hello. I tried to do it your way and everything seems to work except one thing. Once I paste detail(“../nodename”,“iteration”,0) in the Seed value I get error in the origin box's Size parameter. That's what you put in the Seed value, right? Or I misunderstood?
(Error says “Unable to evaluate expression - Syntax error”, and it only happens when I change the Seed value)
@Airlawns: @box_id==`detail(“../nodename”,“iteration”,0)`
Mine:
@box_id==`detail("../nodeName","iteration",0)`
Anyway, when it's correct your VEX will be colour coded. When it's not it will stay white so you know where the errors are (in this case almost certainly to do with however this forum is interpreting quotations).
-
- neil_math_comp
- Member
- 1743 posts
- Joined: March 2012
- Offline
Yeah… because of the quote handling on the forum, I think support for the unusual quotation marks was added to VEX a few months ago, but I don't think it's been added to HScript. (When you use backtick expressions, it's evaluating HScript to find the string. The Group fields themselves don't use VEX or HScript, but rather a simplified syntax, unless you use the Group Expression node.)
Edited by neil_math_comp - Feb. 4, 2018 23:59:17
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
-
- Ben Read
- Member
- 7 posts
- Joined: June 2015
- Offline
I've been following the same tutorial as an introduction to procedural building creation. I've followed your instructions which were great, it actually helped me understand the process a bit better, but I've ran into the problem where in video one part 2 where we create the balcony supports. Anastasia uses the foreach subnetwork node to replicate the process on every primitive that only has 2 direct neighbours. I'm having trouble recreating this work flow so that the number range on the old node is equal to the amount of primitives minus one (nprims(opinputpath(“.”, 1))-1).
Edited by Ben Read - Feb. 7, 2018 22:06:15
-
- mkeir
- Member
- 1 posts
- Joined: May 2019
- Offline
I used a foreach_count loop, then choose iteration method “By Pieces or Points” from the end block. This gives another dropdown of Piece Elements for which you can choose Primitives. I've attached what this looks like below.
I'm now having trouble with the foreach loop on chapter 1 part 3, the roof division. If anyone has a tip on what this should look like, I'd love to see it.
I'm now having trouble with the foreach loop on chapter 1 part 3, the roof division. If anyone has a tip on what this should look like, I'd love to see it.
-
- NidhoggAttam
- Member
- 1 posts
- Joined: June 2019
- Offline
mkeir
I used a foreach_count loop, then choose iteration method “By Pieces or Points” from the end block. This gives another dropdown of Piece Elements for which you can choose Primitives. I've attached what this looks like below.
I'm now having trouble with the foreach loop on chapter 1 part 3, the roof division. If anyone has a tip on what this should look like, I'd love to see it.
im still new to Houdini so i could be wrong.. but for the loop on chapter 1 part 3, the roof division, i just tossed everything she said in a for-loop with feedback, and it seems like its working fine for me, at least to where im at right now
i also would like to know if there's a correct way of doing it other than mindlessly tossing in a forloop nodes lol
-
- johndaniell
- Member
- 2 posts
- Joined: May 2017
- Offline
PlayingKarrdeSailorTwiftI was getting this error too and I think it came from copy/pasting. I wrote it out myself and it worked
@Airlawn
Hello. I tried to do it your way and everything seems to work except one thing. Once I paste detail(“../nodename”,“iteration”,0) in the Seed value I get error in the origin box's Size parameter. That's what you put in the Seed value, right? Or I misunderstood?
(Error says “Unable to evaluate expression - Syntax error”, and it only happens when I change the Seed value)
@Airlawns: @box_id==`detail(“../nodename”,“iteration”,0)`
Mine:@box_id==`detail("../nodeName","iteration",0)`
Anyway, when it's correct your VEX will be colour coded. When it's not it will stay white so you know where the errors are (in this case almost certainly to do with however this forum is interpreting quotations).
You have perfectly right, something has to do with copy - past .. write it manually
![](/static/djangobb_forum/img/smilies/smile.png)
-
- Bleip
- Member
- 1 posts
- Joined: Oct. 2016
- Offline
mkeir
I used a foreach_count loop, then choose iteration method “By Pieces or Points” from the end block. This gives another dropdown of Piece Elements for which you can choose Primitives. I've attached what this looks like below.
Anyone had any luck with this? I've tried to replicate the graph as best I can but it's just not doing what it's supposed to. What's that switch node doing?
Also, are there a load more gotchas in this tutorial series that's going to make the whole thing unbearable?
-
- johndaniell
- Member
- 2 posts
- Joined: May 2017
- Offline
AirlawnYou my friend .. are a lifesaver
I'm still a little confused on the new for each loop myself so I might be doing something wrong but will try and help and maybe better understand it myself by writing it here.
For that tutorial create a for each loop with the end block as iteration method "By Count“ and you are using ”Feedback Each Iteration“ Merge Each Iteration is like the old merge results checkbox.
Set the Block Begin Method to ”Fetch Feedback" and click the Create Meta Import Node. This Meta Input node is how you know which iteration you are in, in the for each loop and I will rename the node "nodename“ just to write something I can refer to later. The Metainput node is just a block begin with the Method set to ”Fetch Metadata" but clicking the button sets up the Block Path for you.
Plug the attribute create which in the tutorial should be labeled box_id into the “Block Begin”.
In the old tutorial you would often be using the stamp function with the for each loop now you are using that meta input node. Call the meta input node and the iteration the loop is in by writing detail(“../nodename”,“iteration”,0)
So in the old tutorial you would be calling the box id value stamp(“..”, “FORVALUE_stackboxes”, 0)+1 the new thing would be detail(“../nodename”,iteration",0)+1.
The locate node "@box_id==`stamp(“..”, “FORVALUE_stackboxes”, 0)`“
would now be ”@box_id==`detail(“../nodename”,“iteration”,0)`" etc.Image Not Found
I hope that works enough to let you continue.
There are some other gotchas in newer Houdini and the move away from the stamp function. I think once anyone me included gets it, it will be a more direct, faster and easy to use method. For now it still trips me up if I am following something and I have to try and create it the old way look at it as I create it the new way.
![](/static/djangobb_forum/img/smilies/smile.png)
![](/static/djangobb_forum/img/smilies/smile.png)
-
- BenjaminMarkus
- Member
- 30 posts
- Joined: Feb. 2017
- Offline
Does anyone know why the Seed detail("../metadata_stack_boxes","iteration",0) evaluates as 2 whereas the stamp("..", "FORVALUE_stackboxes", 0) evaluates as 0? I was under the impression they were supposed to be the same.
This is an example of my code:
![](/forum/attachment/ef335d33437bb63e03abe75362fe39623e69e1cf/)
![](/forum/attachment/1ba34807a5bafe9a4edbdfdb7e499c4a6c691201/)
This is an example of Anastasia's code:
![](/forum/attachment/df8bbea83d4171596bf2d8e93a3a3f5033ba6c16/)
This is an example of my code:
This is an example of Anastasia's code:
Edited by BenjaminMarkus - Jan. 8, 2021 00:52:46
-
- tamte
- Member
- 8555 posts
- Joined: July 2007
- Offline
because stamp() function is only valid during the cooking of the for subnet or old copy sop for that matter, you can't see the evaluated value as it's different every iteration so when observed it's not cooking at that moment and it falls back to the value specified as third argument, so in your case 0
new for loops allow you to observe a single iteration, by default is the last one, but you can pick a specific one so thats why detail() expression is able to resolve the actual value when observed as the metadata node still holds the values that belong to chosen iteration
otherwise your result in viewport seems to be the same, if thats the case, it appears to be working correctly during cooking
(also 3rd argument in detail() is component index, while in stamp() it's the mentioned fallback value, so while they may seem similar when both written with 0, they mean very different things)
new for loops allow you to observe a single iteration, by default is the last one, but you can pick a specific one so thats why detail() expression is able to resolve the actual value when observed as the metadata node still holds the values that belong to chosen iteration
otherwise your result in viewport seems to be the same, if thats the case, it appears to be working correctly during cooking
(also 3rd argument in detail() is component index, while in stamp() it's the mentioned fallback value, so while they may seem similar when both written with 0, they mean very different things)
Edited by tamte - Jan. 8, 2021 01:21:10
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
-
- BenjaminMarkus
- Member
- 30 posts
- Joined: Feb. 2017
- Offline
tamte
because stamp() function is only valid during the cooking of the for subnet or old copy sop for that matter, you can't see the evaluated value as it's different every iteration so when observed it's not cooking at that moment and it falls back to the value specified as third argument, so in your case 0
new for loops allow you to observe a single iteration, by default is the last one, but you can pick a specific one so thats why detail() expression is able to resolve the actual value when observed as the metadata node still holds the values that belong to chosen iteration
otherwise your result in viewport seems to be the same, if thats the case, it appears to be working correctly during cooking
(also 3rd argument in detail() is component index, while in stamp() it's the mentioned fallback value, so while they may seem similar when both written with 0, they mean very different things)
Thanks for the quick reply. Yes this makes sense. I was actually able to get all the way through the first volume of this tutorial, but now I'm having an issue with only certain seeds working, and I've been comparing the two networks wondering if this could be the cause. But, since the viewport output is the same, this seems more unlikely.
As I move through both networks, the other thing that seems like it might be an issue is in the closed balcony section with the treat_body loop. I wonder if I replaced the opinputpath expression correctly by referring directly to the node which the previous opinputpath index 1 seemed to refer (find_closed_balc). They evaluate the same, both as 0, but in this case it seems to make all the geometry disappear.
Here's an example of my network and evaluation:
Here's an example of Anastasia's network and evaluation:
Edited by BenjaminMarkus - Jan. 8, 2021 01:51:31
-
- tamte
- Member
- 8555 posts
- Joined: July 2007
- Offline
the old Foreach if you tell it to start at 0 and end at 0 , then it will do exactly 1 iteraton, iteration 0
the in the new For Loop Block you are telling it to do 0 iterations, so it will not do any and return nothing
so you may need to alter your expression to not and not subtract 1, I'm guessing
the in the new For Loop Block you are telling it to do 0 iterations, so it will not do any and return nothing
so you may need to alter your expression to not and not subtract 1, I'm guessing
Edited by tamte - Jan. 14, 2021 19:32:41
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
-
- BenjaminMarkus
- Member
- 30 posts
- Joined: Feb. 2017
- Offline
tamte
the old Foreach if you tell it to start at 0 and end at 0 , then it will do exactly 1 iteraton, iteration 0
the in the new For Loop Block you are telling it to do 0 iterations, so it will not do any and return nothing
so you may need to alter your expression to not and not subtract 1, I'm guessing
Thanks Tomas! I actually managed to get through most of first volume. I still have one little section left, and hopefully there's nothing too confusing in there. In any case, I was planning on posting fixes to all the gotchyas that seemed to have me stumped before. Figuring out how to translate the old for each subnet to the new for loops has definitely been one of the more confusing things I've tried to learn in Houdini, but I feel like I'm finally starting to get the hang of it. Fingers crossed it gets easier as I move forward through the next volumes.
-
- tamte
- Member
- 8555 posts
- Joined: July 2007
- Offline
BenjaminMarkusI bet
Figuring out how to translate the old for each subnet to the new for loops has definitely been one of the more confusing things I've tried to learn in Houdini
for learning purposes you can always unhide deprecated nodes (until they are fully removed) to be able to follow old tutorials
just open textport (Alt+Shift+T) and type
opunhide Sop foreach
then in Sop Tab menu you should see Foreah Subnet, even though you may have gone through this particular hurdle, it may be useful for other operators in the future as getting stuck can be demotivating, but of course learning the new stuff eventually is way to go
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
-
- BenjaminMarkus
- Member
- 30 posts
- Joined: Feb. 2017
- Offline
tamteBenjaminMarkusI bet
Figuring out how to translate the old for each subnet to the new for loops has definitely been one of the more confusing things I've tried to learn in Houdini
for learning purposes you can always unhide deprecated nodes (until they are fully removed) to be able to follow old tutorials
just open textport (Alt+Shift+T) and type
opunhide Sop foreach
then in Sop Tab menu you should see Foreah Subnet, even though you may have gone through this particular hurdle, it may be useful for other operators in the future as getting stuck can be demotivating, but of course learning the new stuff eventually is way to go
Yeah I totally know that trick and have used it in the past when I was following along and just needed something to work. However, in this case I really wanted to push myself and see if I could translate it. Definitely hasn't been easy, but I learned far more about how Houdini works than if I just used the old nodes and followed the tutorial exactly.
-
- Sabrack
- Member
- 1 posts
- Joined: June 2022
- Offline
Hello there, I'm new in Houdini and I'm learning from different tutorials. I've followed the lake house tutorial and translated it to new code and nodes. My problem is the for each loop node doesn't do what I need. I dont know if I missed something or doing it all worng. As far as I know if I put a merge node inside the for each loop node, every iteration can be merge to create a new geometry merging all previus positions of my box. But my the iterated box change position every time that an iteration occurt, ignoring its previous position in the merge node. I hope I make me clear.
And thanks for your help.
And thanks for your help.
Image Not Found
-
- Quick Links