Creating GoalObjects while KangarooSolver is stepping for custom iteration script


I have been looking at the scripting examples for Kangaroo2 especially ‘custom iteration’ and ‘step by step’ from Daniel Piker (thanks!). I am wondering if it is possible to create new Goal Objects while the solver is stepping forward. Using the catenary Kangaroo example, I wanted one of the vertices in the mesh to snap to a test point when it is close enough. My first instinct was to use a magnet snap, but I couldn’t seem to get it to work. (I tried creating a list of magnet snaps, each one set between one vertex and the test point).

Above: I would like one of th e vertices to snap to the sphere as it is form-finding

Above: Creating magnet snaps

I also started looking at scripting Kangaroo as I thought it would be a more flexible method for doing some custom things. I went through all the examples and understand them well enough. However, in this case I tried to: evaluate whether each particle is close enough to the test point, and if so, create an Anchor GoalObject to clamp its position after calling PhysicalSystem.Step() each time. I did not have success with this either. Is there something I missed in my script?

Above: Edited version of step by step C# scripting example

Above: Code chunk from script. The function CheckDistance is called after PS.Step()

Above: As I step throught solver, I want to create a new anchor Goal Object at the vertex which is close enough to the sphere at this time.

Thanks for any help in advance and the grasshopper definition is attached below (17.4 KB)

The problem in your non scripted version was just that the point being snapped to was not anchored.
So when the mesh snaps to it, the point just moves to where the mesh is, meaning the shape is not affected. Anchoring the point fixes this: (11.7 KB)

That said, I’ll have a look at your scripted version too in a moment, since while it isn’t needed here, I think there are all sorts of interesting possibilities once you start modifying the goal list between iterations.

1 Like

Hi Daniel, thanks for replying so quickly. Ah such a simple mistake with the anchor, thanks for pointing it out. Looking forward to your comments on a scripting approach.

Here’s an example I made a while ago for a particle emitter.
It’s a of bit different application, but perhaps useful as it does illustrate how new particles and goals can be added between iterations: (67.1 KB)

The goals in this example get created fresh at each iteration. The indexing in this case is rather simple since all the particles are treated the same, so it can be assigned directly at creation.

In other more complex cases you might want to actually store the goal list between iterations too, to avoid re-indexing the ones which you’ve already added.


Great, that’s a very cool example. I’ll look through it. Thanks

Dear Daniel,

is it also possible to program it in python?

Best regards,