Exporting geometry to file

I want to write a single Brep to a .3dm file. The brep is not added to a document. However, I get a “‘f.Created’ threw an exception of type ‘System.ArgumentOutOfRangeException’” error even before I add the Brep. The Brep itself is valid.

        Rhino.FileIO.File3dm f = new Rhino.FileIO.File3dm();
        f.Objects.AddBrep(FinalBrep);
        bool writeResult = f.Write(FilePath, 0);
        f.Dispose();

Excuse the german system language, basicly saying “Year/Month/Day DateTime not representable” and “Argument out of bounds” but how could I change that, if that’s the issue?

edit: obviously “writeResult” is false.

Adding

        Rhino.FileIO.File3dmWriteOptions options = new Rhino.FileIO.File3dmWriteOptions();

and changing the Write-Method actually solved the problem.

        bool writeResult = f.Write(FilePath, options);

Final Code looks like this:

        Rhino.FileIO.File3dmWriteOptions options = new Rhino.FileIO.File3dmWriteOptions();
        Rhino.FileIO.File3dm f = new Rhino.FileIO.File3dm();
        f.Objects.AddBrep(FinalBrep);
        bool writeResult = f.Write(FilePath, options);
        f.Dispose();

Hi @rgr,

A sample you can reference.

https://github.com/mcneel/rhino-developer-samples/blob/6/rhinocommon/cs/SampleCsCommands/SampleCsWrite3dmFile.cs

– Dale

1 Like

Thank you @dale, I had my troubles finding a good sample. I wonder why the first code did not work, but I do not recall exactly if I changed more than just the added options. Is “0” not a useable argument for the second parameter of Write()?

Here is the help for File3dm.Write.

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_FileIO_File3dm_Write_1.htm

– Dale