algorithmic modeling for Rhino
Hello,
I'm trying to write a small component which simply saves generic input data and makes it persistent within the .gh file. Problem is, whenever I reload the file or reload the Grasshopper plug-in, the persistent data is reset.
After browsing around, I've tried to override the Read and Write functions to include writing the data. The issue is now that the de-serialization doesn't work and so the component is broken: I get a 'reference to object not set' error upon reading the file, which I suspect means that the data is not initialized before it tries to read to it from the file.
I've made the generic data container an 'IGH_Goo data' variable which then accepts any type of data from the input parameter. In the Read and Write overrides, I simply call data.Write(writer) or data.Read(reader), though this may be a very naive assumption. I haven't had any luck with initializing the IGH_Goo variable (new IGH_Goo() doesn't work).
Any tips on how to save + load generic data from a component would be much appreciated!
Tags:
I simply call data.Write(writer) or data.Read(reader), though this may be a very naive assumption.
Yeah this is risky. Not all types of Goo may support (de)serialization.
I haven't had any luck with initializing the IGH_Goo variable (new IGH_Goo() doesn't work).
IGH_Goo is an interface and interfaces are not objects that can be constructed. You'll have to get the actual type ID of the instances that implement IGH_Goo, and then try to construct those specific types. This is not particularly easy, and it may not work if a type is defined by some plugin which is not guaranteed to be loaded.
Welcome to
Grasshopper
© 2025 Created by Scott Davidson.
Powered by