Passing objects in classes between components

This question has been asked a few times, but I haven’t really found a solution in the answers…

Is there a way to prevent automatic flushing out of objects when creating and passing them inside classes between GHPython components? See a very simplified example below, where I first store a rectangle inside a class, that is passed through a second component to modify one parameter:

But, the curve that is stored in the first component is automatically removed from memory afterwards, so when changing the value of “mass” in the second component, the third component will generate an error:

Is there a better way to do this? Should I use Rhinocommon instead, and how? The fact that I don’t see it covered a lot in the forum must mean that this is not common practice when wanting to create custom Grasshopper components, as is my goal.

I finally found the solution in this thread:

So, I’m just posting a working setup for future reference for anybody wanting to pass geometries between custom classes by what was proposed by @AndersDeleuran and use rhinocommon directly instead and also solve the problem of null object errors:

1 Like

If the question is how to “transfer” (i.e. unbox) custom Types (defined by a class) from one component to another … well … that’s rather elementary.

  1. Define the class on each component. Say:

  1. Declare the List from the “source” component as Type object. Then when in the “target” component do (i.e. unbox so to speak) this:

All the above are C# (because I hate P).