Store Brep as a UserString or as a geometry UserDictionary

Hi,

I have been using Rhino UserString (GetUserString SetUserString) quite a lot and find it super useful. Very often I store additional geometry such as Mesh by serializing mesh.ToJSON()

How does it work with Breps? Can I serialize and deserialize BREP to JSON and store it as a user string? Or I should use UserDictionary to store the object.

The reason to ask this question, is that in Rhinocommon I see Mesh.toJSON() method but there is no BRep.toJSON() method.

Rhino.Geometry.Brep derives from Rhino.Runtime.CommonObject. That gives you the CommonObject.ToJSON Method method.

3 Likes

Thank you.

Rhino is awesome.

2 Likes

Is it possible to check the json string whether it is a mesh of brep?

I serialized mesh.toJSON and brep.toJSON, and stored them in one list.
Now I would like to deserialize them. But you need to call Brep.fromJSON and Mesh.FromJSON explicitly.

AFAIK GeometryBase.FromJSON(json) static method can deserialize the json and create the object back for you.

Thank you. How to cast GeometryBase to Mesh?

Python upcasts automatically, interesting.