Houdini Resources

Updated on Sept 1  2022


copyright © Deborah R. Fowler

For-Each Loops

Deborah R. Fowler



Houdini Looping - For Each and Variation - also Copy Options link

Posted Aug 11  2019
Updated Sept 2  2022
Updated Mar 8  2024

Houdini is multilingual. In particular, you can communicate with hscript, vex, vops (pictoral vex), python and less commonly C++ (HDK). If you are not familiar with the concept of looping, please see my introduction to programming.

There are many ways to create loops in Houdini including the for-each loop.

This page is intended to go over the for-each node, however it is useful to understand the copy nodes beforehand.
I have created a new hip file in 19.5 that is designed to introduce a variety of the options for copying/looping. (Note instancing is covered as a separate topic).


CONTEXT NOTE:
The copy stamp node has been a very versatile node (which I refer to as the copy node) and was a superset of the copy transform and copy to points nodes. Functionality was added to the copy to points node that allows variants (explained below) and the copy to curves node was introduced. In addition, for-each, wrangles (vex) and python appear. Further distinctions are made between implicit and explicit loops with regard to vex and vops but that is a top for more advanced users. For beginning users, focus on the container with postfix Beginner.

As of Houdini 19.5, the copy stamp node is no longer available from the tab menu. The documentation recommends using for-each instead (https://www.sidefx.com/docs/houdini/copy/stamping)

Yes, you should use the for-each instead, yes copy stamp is not as efficient for variants ... but should you ever need it for a reason it is still around until it is fully deprecated via textport (Technical Desktop or go to menu Window/hscript textport ) - create a geo node and then type in textport:
opcf /obj/geo1; opadd copy

opcf will Change Folder - you can also use opcd instead (coming from a linux background this is easier to remember). These can be type on separate lines as well.

opcd /obj/geo1
opadd copy

In fact you could create the geo, copy and sphere node setup by typing
opcd /obj;
opadd geo; opcd /obj/geo1; opadd copy; opadd sphere; opwire /obj/geo1/sphere1 -0 /obj/geo1/copy1
There are many commands you can use in textport (opset -d on /obj/geo1/copy1 would turn on the display flag), but you have an excellent gui so this would more likely be used for scripting, and you are more likely to use python - if you are interested there is more information on python in Houdini click here.

You can also use a textport command to make the copy with stamp node available in the tab menu in your geo container
opunhide Sop copy

You can also copy it from the example files with ctrl-C ctrl-V

Many ways to do things in Houdini!

On this page I will mainly describe the for-each loop. Please see my page on wrangle nodes for the examples shown without the for-each node construct, but hscript, vex and python (or the example above):
Other examples such as using a circle of sphere and the phyllotactic pattern in point wrangle and python can be found on my website as well.

The for-each construct is used here to make a circle of sphere, phyllotactic pattern, and a snowman.
Example file is circleOfSphereAsForEach.hipnc

In this case the "meta" data is used to grab the iterator so that is can be used similarly to the copy number.
In the tab menu there appear For-Each Connected Piece, Named Primitive, Number, Point and Primitive. These are simply presets and you can select the options from the parameters in the for-each nodes.





Other uses of for-each are when you are using "parts" of the specific geometry.
 
Note that the Houdini documentation has some excellent examples as well. There is an example of a copy star copied onto a sphere in the SideFX documentation.
Since the file did not appear in 17.5 help files, I have created a version to get you started here.
Also, a soccer ball example from SideFX video and start file.

Copy stamping is no longer recommended for variation (https://www.sidefx.com/docs/houdini/copy/stamping). This can be achieved more efficiently with for-each or vex/create attribute/instancing.
MISING IMAGEMISING
        IMAGE

MISSING IMAGE

Remember to use packed geometry.