Grasshopper

algorithmic modeling for Rhino

How to prevent two geometry collections from merging when inputted as single variable in scripting component?

I would like to input an arbitrary number of geometry collection components into a single variable of a Python scripting component. However, I would like the variable structure to contain them as individual lists inside a larger list. 

So instead of each individual geometry being considered an element in this list, given an input as pictured below:

Then I would like to get the following structure for variable 'x':

x = [ <geometry collection 1 GUIDs>, <geometry collection 2 GUIDs> ]

where x is a list. 

Is this possible in Grasshopper, and if so, how do I do it? Right now I've gotten as far as grafting inputs and setting the input to List Access, but this only gives me a list of individual geometries (i.e. each line or point is considered an individual element), i.e.:

x = [ <GUID of line>, <GUID of line>, <GUID of point>, ...]

UPDATE:

Based on the replies I've gotten here, this doesn't seem to be very in line with Grasshopper's behavior, so I've taken another route. Instead, I've created a component that turns each geometry collection into sets of data first before they are combined as individual objects into one input, so essentially:

x = [ <geometry 1 object>, <geometry 2 object> ]

Then I just let Grasshopper do the enumeration for me given multiple connections to one input in a component.

Views: 92

Reply to This

Replies to This Discussion

Hello,

you mean tree access, which is basically a list of lists?

# input tree of pts

for i in range(pts.BranchCount):

  #as List

  mybranch = pts.Branch(i)

  #or access each item:

  for j in range(pts.Branch(i).Count):

   myitem = pts.Branch(i)[j]

I've set my type hint to GUID and enabled List Access. I'm getting a result wherein each individual geometry is stored as a branch, rather than each collection of geometry being stored as a list inside a branch. Say I had two geometry collections with 14 objects each, which makes for 28 geometries. Is there a way to retain each geometry collection's list as individual branches rather than them getting turned into individual branches per geometry?

I.e. when i check what pts.BranchCount outputs, I get 28 instead of 2.

well you need setup your tree the right way. If you graft them at input you get by having 28 objects 28 branches. If you set up a tree with 2 branches and 14 elements each your branchcount will be 2. There are hundreds of ways in setting up a datatree. You can do it before your script or within your script:

have a look

Attachments:

I would like to input an arbitrary number of geometry collection components into a single variable of a Python scripting component. However, I would like the variable structure to contain them as individual lists inside a larger list. 

This is counter to the way Grasshopper usually works and I recommend against it, if only to reduce user confusion. There is an object in standard GH which does this btw; the Quick Graph. It does not merge inputs in the way you expect, instead it treats each source as separate from all others. However this behaviour is really hidden and since the QuickGraph has no outputs it's not of consequence to anyone.

If you really want to do this, you'll have to access the sources individually from within your code. You cannot put Humpty back together by only looking at the [x] input, no matter what flatten or graft options are on it. The data inside [x] has been mashed together and there's not enough information to undo that.

So you'll have to ignore the x input, look directly at the individual sources and make sure all item/list/tree looping is done inside your code. This is a lot of work and it's difficult.

Instead of doing this inside the python code, use an [Entwine] component instead.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2018   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service