Houdini allows 'spare inputs' into a SOP node, which lets you reference external data from inside a For Each loop.
For an example, let's say I want to scatter some points around the vertices of a grid. I want a random number of points at a random distance from each vertex.
I can create attributes on each vertex to control number of points, radius from vertex and random seed. I can then move that data to the scatter node using Spare Inputs.
Here I have got three wrangles creating data on each vertex on a grid.
f@size = fit01(rand(@ptnum), ch("size_min"), ch("size_max"));
i@number = int(fit01(rand(@ptnum), chi("min"), chi("max")));
f@seed = rand(@ptnum + ch("seed"));
The data created will be different per vertex, because of the rand(@ptnum) function
Inside the loop, on the sphere node, I reference the 'size' attribute to create a different sized sphere on each point on the original grid. To get that data from the loop node into the sphere node, use the Spare Input:
From the config 'cog' menu on the Sphere node, choose 'Add Spare Input'.
This creates a new slot in the Sphere node. Into this slot, drag in the top For Each node from the loop
You will see a purple connecting line in the network graph from the For Each node into the Sphere node. This line indicates that there is a connection into a spare input.
In the Sphere node, I want to look up the 'size' value for each vertex on the grid and use it to scale the sphere. To do this, I use the 'point' function, wth the first parameter being -1, which tells Houdini to look at the first spare input.
point(-1, 1, "size", 0)
Here I am looking at the first spare input, then the first object in that input, then look for the attribute called "size" and choose the 0th component of that value. It's a scalar value, so it just fetches the value
Next, I have used a Scatter node to make some particles inside each of the spheres. The number of particles in each sphere is a random number per vertex, generated by the second of the wrangles.
Again, I created a Spare Input to fetch the data from within the For Each loop.
So, I now have a random number of particles created around each vertex of the grid.
However, you can see that the distribution of particles is repeated for each group. I want each scatter to have a random seed. I can do this with another attribute passed into the Spare Input. I don't need to make a new Spare Input, I can use the same one, but just change the point function:
So, it's possible to pull any number of attributes through a single Spare Input.
In this case "seed", "number" and "size" are all passed into the For Each loop via Spare Inputs on the Sphere and Scatter nodes.