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: 653

Replies to This Discussion

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.

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

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service