Grasshopper

algorithmic modeling for Rhino

Public Overrides Function CastFrom(source As LIST OF WHATEVER) As Boolean

I'm writing a custom class/goo/parameter and I would like to cast list of objects to one object of mine.

Which means I would like my parameter to be set to GH_ParamAccess.Item (so that it processes my custom class once, but if there is a list of let's say points , it should cast them onto ONE custom class - say it point cloud).

From what I see CastFrom is called for every object in the parameter... should I mess with overriding custom parameter's CollectVolatileData_FromSources ?

Thanks in advance.

Views: 451

Replies to This Discussion

Hi Mateusz - 

Yes, it seems to me the only way to do this is to override CollectVolatileData_FromSources. CastFrom only ever has access to one piece of data at a time.

I did a little test of this - it is a lot of work to just get the behavior you're describing. Assuming you're going to use this single-object-data inside a component, what's so bad about just getting the param data in with tree access, and converting the whole lot into your custom object internally?

That said, if you really want to create a param that turns many items into one item, I've attached an example of how to implement the _Goo type and the Param in such a case.

(Full disclosure - I only kind of understand what I'm doing so use at your own risk!)

I've set the param to only ever maintain ONE item at all - which means if you feed in two CustomCollections into the same param, you get one CustomCollection out. It will totally blow away any data trees being fed into it.

If you want to be able to hold multiple instances of your CustomCollection type in one parameter, you'll have to modify my logic further. You can see where it would quickly get sticky - how to handle the case where you're feeding in multiple sets of Points from different params and multiple instances of CustomCollection? should the points all become one new one while the others stay distinct? should the points merge into one of the CustomCollections, and if so which one? I didn't have good answers for those questions but maybe it's clearer from what you're trying to do. 

In any case - hope this helps. 

Attachments:

Thanks.

I have to say that sometimes the data trees are quite limiting ;)

I share your doubts over multiple collections behavior. 

So curious to know what you're cooking up!

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service