algorithmic modeling for Rhino
Good day everyone, hope that you are well and happy.
I keep getting stuck on data management it seems and I am thankful for any help with the following issue:
How can I find out the number of times a certain vector is repeated in a list? Ideally, I would like to know (if there is any repeated data) what is it, and how many times, and then which of the vectors in the list is the most repeated one.
The screenshot attached is showing the current set of vectors I have.
I am thinking that perhaps I can somehow cull all vectors except 1 type, and loop the process, getting separate lists of different sizes which I can measure. However I am not sure how this can be done actually in grasshopper.
Or perhaps I can run a loop that will count the number of times a certain item is equal to another item. The loop would omit any items that were already counted every time it runs. However again I am not sure how this can be done in grasshopper.
Thank you everyone for your help and this amazing support base that without which I wouldn't dream to learn grasshopper.
Wish you all a great day.
Tags:
Yep, Danny has got you set up. Unfortunately, traditional methods of programming using loops don't work in Grasshopper. You have to manually pretend to have a loop, as Danny has done, by searching your data for something, then using the results as a key or index, pull out the data you need or count the data you need, etc.
People will say you can do loops with Hoopsnake, but that's not nearly the same as a loop in Java or Matlab, for example.
Have you tried. http://www.grasshopper3d.com/group/anemone
I have. And I agree, it does add some nice tools to our collective belt. My point was just to say that traditional programming is built entirely around for, if, while loops. And these plugins can help address that, but as of yet they aren't perfect substitutions for good old fashioned logic loops.
I think it should be pointed out that certain types of Loops are not unattainable in Native GH.
Just recursive ones where it relies on something to previously have been answered in the same process.
Every Component's inputs are For Each Item type loops.
for example to convert an integer into a Binary requires a do while loop of code
This is Ander's Answer to the most recent ghoffee question
if n:
b = ""
while (n>0):
nm = int(n%2)
b = str(nm)+b
n = (n-nm)/2
else: b = "0"
Where as a Native GH Approach is still achievable and similarly the reverse process. The key to achieving this is to have components such as [Join Text] and [Mass Addition] which can take multiple inputs and produce a single answer.
So in summary: provided that the multiple inputs can be preset then a for each loop is achievable
Yeah I am starting to understand this, and it is actually an interesting experience to readjust to a new method of programming (to think Grasshopper, I mean), although I am sure that grasshopper will keep on growing and thus the method itself will keep changing.
I really think that loops are a very essential component of many programs, and as such I have actually integrated both Anemone and Hoopsnake in the project I'm working on, but still I am having issues such as retrieving information that occurred within a hoopsnake loop after exiting the loop for example. Which has led me to the current issue you guys helped me resolve, where I was basically trying to reverse engineer the products of the hoopsnake loop and anemone loop in order to get back to the information that was generated somewhere in the middle of the loop.
Thank you very much Danny for the method which works perfectly. I just find it a little difficult to learn the data management methods in grasshopper because I don't really understand the pattern. What I mean is, I would never have guessed that the member index component would have the ability to provide a count.
Thanks again! ^^
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by