Grasshopper

algorithmic modeling for Rhino

List dispatching to multiple streams in non regular pattern

Hi there.

I should probably start stating that I'm not an advanced user but an enthusiastic one. Just starting to understand data/lists management but still a lot to learn.

The problem is that I have a list of coordinates which I need to sort in groups as per a series of numbers in another list. Both are txt files which I'm reading to bring a series of points in but those points are generated with a corresponding index.

Of course the lists are not sorted in any way, but the numbers are corresponding so it looks like a series of 9, 6, 7, 2, 8, 0, 9, 5, 6, 4, 2, 3, 8, 5, 5, 6, 9, 4 in one file( and series of (X, Y, Z) coordinates in the other.

The question is how can I make it to sort the list and then split it per index... if it is possible... or should I just do this in excel and bring clean lists in?

My idea, if it works, is use the series of points to generate paths and work with them.

I'll attach the lists just if it helps making a clear idea.

Any advice will be very welcome.

Views: 2259

Replies to This Discussion

Well, There goes the files...

Attachments:

Hi Arturo,

I don't quite get it. You want to find all the points that use the same index? Or do you want to sort them somehow?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

It's just finding them out.

They are already sorted from first to last but mixed with the others. We could say something like:

the first belonging to thread 1

the first belonging to thread 20

the first belonging to thread 5

The second belonging to thread 1

the first belonging to thread 3

The second belonging to thread 5

(and so on)

.

.

.

Then, if I find and group all the ones belonging to thread 1, if they have been processed in the same order the list is, they should be in a sequential order anyway.

Thanks!

This works, but ...

Really what you want would be like the inverse of the Weave component. A branch histogram builder.

I've been wanting such a component for a while. Something that basically takes a pattern of indices, input data, and groups the incoming data into branches based on index numbers, and would hopefully be less costly than this, which has to test every single item against a fully known set to produce the correct output.

Here's the code in Python:

import Rhino
# for accesssing GH classes
import clr
clr.AddReference("Grasshopper")
from Grasshopper.Kernel.Data import GH_Path
from Grasshopper import DataTree
dataTree = DataTree[object]()
for i, thing in enumerate(data):
branch_id = branch_ids[i]
path = GH_Path(branch_id)
dataTree.Add(thing, path)
a = dataTree

Awesome.

I knew there was a way and I just wasn't getting it.

Thanks a lot!

(I still can't make the python stuff to work but the other way does the trick)

David, could we have a component that does this, when (if) you have time and it seems reasonable?

Never mind, here's the solution:

And, by the way, I'll take this into my collections... what an elegant solution!

Yep, you´re totally right. I though it could be possible with the Stream Gate component, if it was able to take more than a single value per Gate, but it is not...

I don't know a word of Python so, by now, unless somebody gets to a very clever way to do this, which I haven't found yet, I'll try to sort it out in the source (Processing), generating series of lists, which will be hard to import but I'm sure I'll be able to generate some string series stuff that could help a bit.

here

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service