Grasshopper

algorithmic modeling for Rhino

I'm trying to split a list of objects up by their type. Their indexing doesn't matter, so I'm just throwing them into bins.

This problem seems very similar to Eirik K's problem(spooky that they start life as neighbors.)

Here's the code, it has sample data, so all you need to do is paste it into a PY component and then inspect the results.

#test data
types = ['Polyline Curve','Closed Curve','Closed Planar Curve','Curve','Planar Curve']
typeList = ['Closed Planar Curve', 'Closed Curve', 'Planar Curve', 'Polyline Curve', 'Closed Planar Curve', 'Planar Curve', 'Closed Curve', 'Polyline Curve', 'Closed Planar Curve', 'Planar Curve', 'Closed Planar Curve', 'Closed Planar Curve', 'Closed Planar Curve', 'Closed Planar Curve', 'Closed Planar Curve', 'Closed Curve', 'Polyline Curve', 'Polyline Curve', 'Planar Curve', 'Closed Curve', 'Closed Planar Curve', 'Planar Curve', 'Curve', 'Curve', 'Closed Curve', 'Closed Curve', 'Planar Curve', 'Closed Planar Curve', 'Polyline Curve', 'Closed Curve']
#the meat of it
bins = []
for t in types:
    bins.append([])
for i in range(0, len(typeList)):
    for j in range(0, len(bins)):
        if typeList[i] == types[j]:
            bins[j].append(typeList[i])
print bins
a = bins

Does anyone have any idea how to make it return the contents of the list, and not a list object?

Views: 2343

Replies to This Discussion

Hi Ben

Grasshopper never accepted enumerables of enumerable types, as it already has the Grasshopper tree structure that is meant to fit that purpose. You need to either look for discussions about the way to construct Grasshopper trees from scratch (there are some also for GhPython), or more simply choose a logic with which you can return a single list as result. For example, have 5 component outputs, one for each items in 'types': this allows to have a single item input and do the logic in the script for a single item. Grasshopper then reconstructs the tree from the single iteration logic.

Giulio

Hi Giulio,
Thanks for the reply. The idea is that I have a bunch of outputs from an operation, and I'd like to deal with each in a different way (the easy way for the easy stuff, the hard way for the hard stuff etc.). To keep it generic, there is no way to tell how many different types of thing go into the code, so instead of making n outputs for each type*.

I found one of your examples of how to make a datatree and tried to tweak it to make branches. I'm missing the step to make more than one branch though. How do I make each type get it's own branch?

 

updated code

On an unrelated note, is it possible to embed a gist?

*it'd be interesting to see how many that'd actually be!

Ben, as a courtesy, would you please upload the file?

hey ben, i'm running into exactly the same problem. did you find a way around this? 

best 

d

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service