RhinoDoc.WriteFile doesn't release the file after writing?

There is a temp .3dm file which i’m writing with WriteFile(path, options) method. It return true, and after that i want to delete the temp file with System.IO.File.Delete(path) and it throws an exception.

Exception Message:
“The process cannot access the file ‘…Temp\RhinoTest_tmp.3dm’ because it is being used by another process.”

Hi @gabor.konstanzer,

You may need to provide some source code, that we can run here, for us to be helpful.

Thanks,

– Dale

Okey, it is basically a Rhino 6 bare bones template in Visual Studio 2017 and i wrote this inside the RunCommand(doc, mode)

[Runcommand code in Pastebin](https://pastebin.com/nqiY8G5f)

Thanks,
Gabor

Hi @gabor.konstanzer,

Rather than calling the document’s WriteFile member and having to deal with it’s file locking, you might just script the SaveAs command. Here is an example.

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

– Dale

Thank you very much, i’m gonna try it tomorrow.

Hi @dale

I checked your suggestion, my problem is that i’m calling the Doc.WriteFile from a service class which is saving the file temporarily and then wants to delete it. This wasn’t a problem in Rhino 5 and is a problem in Rhino 6. I think this script.runner solution is not meant to used like that. So any other suggestions why it locks longer then it used to, or how to get around the locking issue?

  • Gabor

Hi Gabor,

I have logged the issue.

https://mcneel.myjetbrains.com/youtrack/issue/RH-44225

Until this is resolved, you may want to use the script runner solution that I proposed (above).

Thanks,

– Dale

Thanks, will try to do that. My question then is that i create a Scripted save Command, and i can call that command from my Plugin?

Yes

– Dale