BeginSaveDocument Firing Multiple Times

Hi,

I’m doing some research to save my custom plugin data before Rhino saves the 3dm file and I noticed that the event BeginSaveDocument and some overrided methods are being fired 2 times when doing a CopyToClipboard (CTRL + C) command and only 1 time when calling a SaveAs command. Here’s my command line output putting a Writeline into each event/override:

Command: '_CopyToClipboard
RhinoDocBeginSaveDocument
ShouldCallWriteDocument
RhinoDocBeginSaveDocument
ShouldCallWriteDocument

Command: _SaveAs
RhinoDocBeginSaveDocument
ShouldCallWriteDocument

Maybe other methods are being also affected since I didn’t check all events/inherited methods from the Plugin class.

Regards,

This is true, as Rhino writes multiple temporary files to support copy/paste between different versions of Rhino.

– Dale

That makes sense, thank you @dale!

Regards,

Hi Dale,

Since CopyToClipboard causes temporary files to be written, it also calls the WriteDocument method in my plug-in. Is there a way to know that WriteDocument is being called from CopyToClipboard vs say a Save As… Rhino 5 file? The only write options I see that appear to be different from a normal call are that IncludeHistory and IncludePreviewImage are false but I assume that is not a reliable way. The reason I ask is because I would like to do something different in the two cases.

Thanks, Larry

Hi @LarryL,

You might define a Command.BeginCommand event handler that watches for the CopyToClipboard command.

– Dale

Thanks Dale. I ended up doing something similar; looking at the command stack and checking for the CopyToClipboard command.

can you help with some sample of python code that shows how to use event in Rhino python

I want to run a command before saving a file.

This example should help you get started.