Iterate through all and pick best

I want to iterate through a list of data. After each run i want to pick the best option and jump into next list index.

Lets say i have a list of curves and a list of lines. I want to:
1.pick the first line, rotate it 0-90 degrees (1deg jump each iteration)
2. pick the one with smallest amount of intersections and save it
3. Jump to a next line
4. Repeat steps 1-3 until i am out of lines

I’d like to use Anemone for that and have a problem with step 2. Do you have any ideas how to pick and save and choose best line rotation?
I thought about using ‘constant output’ for loop end and a data recorder that would construct branches depending on loop counter. Later i would sort each branch (by number of intersections) and pick the first item of each branch.
That is kind of heavy and messy on the other hand. Is there another way that i am missing?


You could do this with Python otherwise. It is easy to loop on a list of objects and has built in functions like min() to help you find the least interactions.

Don’t know about Anemone, but since you cannot economise on the number of intersections, the only benefit of a one-line-per-iteration approach is that you never have all the lines in memory at the same time. Lines are pretty cheap, so that’s not a huge saving.

I’d say, just create all lines, keeping the associated rotations together in lists, then intersect all lines with all curves, count number of intersection points, sort by count, extract first line from each list.

That is true but I only made an example to illustrate the problem. In fact I am operating on huge amounts of breps and booleans (eh) and step by step approach is crucial as the group of breps (illustrated by curves - not lines) is different for each step. I just wanted to make things easier to understand as the rule would be more or less the same

Thank you for your reply,
Unfortunately I am not familiar with Python (or any other programming language) so a loop (+probably a nested loop) is too much to handle for me right now :frowning:

No, it’s not a problem for any solver, i need to use a loop for that

Rather more. Load R file first and see attached (A classic ccx Clustering puzzle plus a loop more [rotate] to suit your goal).

Curve_ccxCurve_Sort_V1.3dm (49.2 KB) (124.6 KB)

Bad news: 100% code based solution (but the logic is simple).

Ugly news: Lot’s of equal value (ccx Events) solutions are more than possible.

1 Like