Get Rhino3dmIO geometry to Rhinocommon Rhino.Geometry

I am just getting started with Rhino.Compute.
I am running compute locally.

I developed a Test .rhp plugin. For example,What I am trying to achieve is when user enter command “Make_Sphere” Sphere should be created by Compute and not by Rhinocommon. Geometry is getting created by compute after command is used, however I am strugling to bake that geometry created by Compute in current rhino document. I cannot use RhinoDoc.Objects.Add…(…) as Compute generated geometery is Rhino3dmIO geometry. Is there a way to solve this?

In the end ,user shall give inputs (geometry and numericals) on being asked by commands/buttons. This input data would be send to compute for solving the problem and output is showed to user in current active document. Therefore conversion from Rhinocommon objects to Rhino3dmIO objects and vice versa is needed.

I hope I am making sense.
see images below.

this is what I did to solve the problem but I think it gets messy when I have thousands of objects of different ObjectType. Is there a better way to do this?

Thanks in Advance!

    public Mesh ComputGeneratedMesh { get; set; }

    public String JsonInfo { get; set; }
    //public GeometryBase GeomB { get; set; }
    public DoSomthing()
        var sph = new Sphere(Point3d.Origin, 12);

        var mesh = MeshCompute.CreateFromBrep(sph.ToBrep());

        this.ComputGeneratedMesh = mesh[0];

        SerializationOptions op = new SerializationOptions();
        op.RhinoVersion = 7;
        this.JsonInfo = this.ComputGeneratedMesh.ToJSON(op);

and then from RunCommand method:
DoSomthing dSm = new DoSomthing();

        string jSonInfo = dSm.JsonInfo;

        Mesh msh = JsonConvert.DeserializeObject<Mesh>(jSonInfo);

        if (msh != null)

This works “serialize and deserialize”

You shouldn’t reference Rhino3dmIo in your plug-in. Just reference RhinoCommon.

You should not have to perform conversions to json and back from json.

1 Like