RhinoCommon RhinoDoc.WriteFile Method

Trying to call RhinoDoc.WriteFile method from my plugin … always returns false.

sample code.

    protected override Rhino.PlugIns.WriteFileResult WriteFile(string filename, int index, RhinoDoc doc, Rhino.FileIO.FileWriteOptions options)
                string tempfile = System.IO.Path.GetTempPath() + "temp.3dm";
                    if (doc.WriteFile(tempfile, options))
                        //code follows
                        return Rhino.PlugIns.WriteFileResult.Success;

                return Rhino.PlugIns.WriteFileResult.Failure;

Maybe the recommended way of making a file name will help?

using System.IO; // now you don't have to write the full namespace
string tempfile = Path.Combine(Path.GetTempPath(), "temp.3dm");

Then, it may be that there is already a temp.3dm in the temporary directory and the doc.WriteFile does not want to override it in fear of losing valuable data.

@menno Thank you for the suggestion.
But still returns false. I have ensured that there are no temp files and even tried writing to a different location.

Hi @rajeev

The WriteFile method is a virtual function available on plug-ins that inherit from Rhino.PlugIns.FileExportPlugIn

During saving or exporting, if the user picks your file type, Rhino will call your FileExportPlugIn.WriteFile override, along with the appropriate parameters.

Why are you trying to write a 3dm file from within your file export plug-in?

– Dale

Hi Dale,

The actual translator is an external program with many other dependencies and hence did not want to create a monolithic plugin program.

BTW the external program depends on OpenNurbs … still waiting for a v6. This plugin would simply write the contents of the current document into a temporary 3DM archive file, call the external program which would then do the translation and handle back the exit codes to the plugin.


Hi @rajeev,

If Rhino is in the middle of a file write operation, which it is when it calls a FileExportPlugIn.WriteFile override, then calling RhinoDoc.WriteFile will fail.

Does this help?

– Dale

HI @dale,

Thank you … I understand, Is there any other method to write the contents of the current RhinoDoc to a temporary file.

I can always figure out the current file path and use that instead… but the problem is what happens if the user wants to “export selected” instead of SaveAs…

Hi @rajeev,

I know of no function in Rhino that allow you to save the current Rhino document while Rhino is in the middle of a file saving operation.

– Dale