Exports and imports using Rhino Compute

I started to play with Rhino Compute, many thanks for making this possible!
One of the ideas that came up so far: It would be extremely useful to have the possibility to run exports and imports via Rhino Compute. Ideally this would work using all file formats supported by the importers and exporters included with Rhino. My goal is to implement GH components which allow to stream in/out data in various file formats. Looking forward to your feedback.

1 Like

Totally agree; I put some work into V7 to make this possible, but still have more to do in this area. My hope is that you will be able to read any file format that Rhino reads and write to any format and in general I think it will be possible.

I have logged this at
https://mcneel.myjetbrains.com/youtrack/issue/COMPUTE-26

1 Like

Have you had a chance to look into this yet? We are starting to work on ShapeDiver for V7, this would allow us to improve the import and export capabilities.

Yes, do now support import and export of different formats through RhinoCommon. Here is a small sample I posted for SVG (all formats work the same way)

That’s great new, many thanks, I will check it out asap.

@stevebaer are there still plans to have this feature in Rhino Compute / Rhino3dm?

Yes it is planned. I personally just haven’t had enough hours in the day to get things like this completed.

1 Like

Great!
Alternatively, I should be able to expose additional Rhinocommon functionality if I spin up my own RhinoCompute server, right?

Yes, that is a possibility.

1 Like

@stevebaer
I’m trying to add an export endpoint to our installation of Rhino Compute server.
The Rhino Inside function that I’ll be using to get the STEP export is:
Rhino.FileIO.FileStp.Write(@".\box.stp", doc, options );

Now this works given a valid Rhino Document like using var doc = Rhino.RhinoDoc.Load(path)

Since this will be an endpoint, Ideally I would like to send the document object with a post request from a python or javascript client. But unfortunately I haven’t found a function to create a document using the Rhino3dm or Compute_rhino3d python clients. I’ve only been able to make File3dm objects using : model = rhino3dm.File3dm()

I know I can write that file to disk on client side, send it with a post request to the server, write it to the server disk and load it as a Rhino Doc. But I was hoping to avoid the redundant writing and reading from disk.

Is there a way to get a document object from the client side, encode it and decode it on the server side?

1 Like

Hi Steve,

I’m trying to do this on our customized installation of Rhino Compute but I’m getting a dialog saying “this dialog requires RDK to be loaded” (see attached screenshot).

here’s my code:

var doc = Rhino.RhinoDoc.Load(path);
doc.Export(Path.ChangeExtension(path, "svg"));

Edit: I checked the options in my Rhino WIP, and the Renderer Development Kit is enabled.


I suspect that is because the SVG exporter isn’t smart enough to know that it is running in a “headless” mode and is attempting to show UI for defining a bunch of export settings. I’ve added this to our bugtrack list at
https://mcneel.myjetbrains.com/youtrack/issue/RH-57097

Understood, Thanks for adding it to the bug tracker.
While we’re at it, I encountered another problem with RhinoDoc.Export() in general. It seems like it’s not meant to be used headlessly.

In many extension in doesn’t work. For example while Rhino.FileIO.FileStp.Write(exportPath, doc, new Rhino.FileIO.FileStpWriteOptions()) writes a valid step file, the Export() method seems to call the step exporter but it just hangs there.

RH-57097 is fixed in the latest WIP

1 Like

Thank you @brian!
I see that the view defaults to top. This is probably enough for what we’re doing now, but is there a way to specify a different view for the svg export?

I added your request here:
https://mcneel.myjetbrains.com/youtrack/issue/RH-57340

1 Like

I was wondering about the current state of the original question. I’d like to write some Python code that takes different filetypes (like dxf, svg, pdf) and using Rhino compute converts it into a 3dm file to use in Rhino 6.
Looking at the docs it seems there is no import method apart from the File3dm ones. @stevebaer added a tracker for this back in 2018, but is support for import/export on the roadmap for rhino3dm (specifically the Python version)?

This should be technically possible now. We haven’t baked the feature into compute yet, but you could do this with some custom code.

Wondering if there is now some sample code to import a stl or dwg using rhino3dm or rhino.compute?

Hello Robert,
Here are a few samples:

The latter includes a C# script component in the gh definition with the following code:

    if( null == data || null == ext ) return;

    var decodedData = Convert.FromBase64String(data);

    var tmpPath = Path.GetTempFileName();
    tmpPath = Path.ChangeExtension(tmpPath, ext);

    Print(tmpPath);

    File.WriteAllBytes(tmpPath, decodedData);

    if(File.Exists(tmpPath))
    {
      using( var doc = Rhino.RhinoDoc.CreateHeadless(null)){

        doc.Import(tmpPath);

        var ros = doc.Objects.FindByObjectType(Rhino.DocObjects.ObjectType.Mesh);

        Print("Number of meshes: {0}", ros.Length);

        var meshes = new List<Rhino.Geometry.Mesh>();
        foreach( Rhino.DocObjects.RhinoObject obj in ros )
        {
          meshes.Add(obj.DuplicateGeometry() as Rhino.Geometry.Mesh);
        }

        A = meshes;
      }
    }

So as you can see, you pass a b64 encoded file (stl, dwg, or whatever Rhino supports), you save that file on the server, you create a headless doc, and you import the file into the headless doc. You should tailor this example to handle the objects you are interested in.