I am developing a compiled C# Grasshopper component (GHA) and I have a specific requirement where I need to “internalize” some static Curve geometry directly inside the DLL. Essentially, I want the component to instantiate with this geometry pre-loaded, without the user needing to input it or reference an external file.
I have tried a few methods to serialize the geometry into a string to hardcode it, but I’m hitting some walls:
-
JSON: I tried
curve.ToJSON(new Rhino.FileIO.SerializationOptions()), but re-instantiating it inside the component often returns null or invalid objects. -
Base64: I attempted to convert the geometry to a Byte Array and then to a Base64 string, but I suspect I am using the wrong serialization class (standard .NET BinaryFormatter vs GH_IO).
My Question: What is the robust, standard way to embed Rhino.Geometry.Curve data inside a compiled component?
Should I be embedding a .3dm as a Managed Resource and reading the stream, or is there a reliable way to serialize the curve to a static string (Base64) that Rhino.Geometry can reconstruct reliably?
Any snippets for the serialization/deserialization workflow would be greatly appreciated.
Thanks!