Export 2d Curves to JSON metadata

Is there a way to convert curve to a json metadata using Rhinocommon? I’m developing a script to convert shapes(can be irregular shapes also) to a json data file which could later be reproduced to recreate the curves.

I was thinking of retrieving the points at discontinity and adding these points to the json file. The discontinuity can work for polygons. Whereas for circles I could split the circle curve at a fixed length to get all the coordinates that could be redrawn. But I’m not sure when the shapes are more complex which involves both straight curves and spline what can be the best way. Can I have a suggestion on this if there could be a different approach to tackle this problem?

Curves, as with anything that inherits from CommonObject have a handy little ToJSON() Method you can use for this purpose.

I wrote an example here of serializing/deserializing a while ago;

1 Like

thank you! This worked. Just to add to the previous question.

Can I also include the user strings attached inside the JSON? Currently, I can reproduce the curve but not its user string.

Hey @sujal Are you adding the User String to the CurveObject or the Curve?
If you add it in Rhino, it adds it to the ObjectAttributes, before you serialize you could of course take the Objects User Strings and add them to the geometry, then serialize. Ensure you duplicate the Curve it before you add the data or you’ll end up duplicating data in your document :slight_smile:

1 Like

yes, thank you.I have been adding attributes to CurveObject. I have to assign the user dictionary to curve instead and then serialise it.