Copy-Paste Firing Doc Begin and End Open Events


Not sure if this is ‘expected’ behavior…Using RhinoCommon and have added event handler BeginOpenDocument and also EndOpenDocument when my plugin loads, also have override function ShouldCallWriteDocument to test to see if need to serialize plugin data or not…all works as expected when opening and saving documents but have noticed that when I do copy to clipboard any geometry (either via CTL+C or via edit,copy) the ShouldCallWriteDocument function gets called (twice as matter of fact) and when pasting geometry (CTL+V or edit,paste) the BeginOpenDocument and EndOpenDocument events are called.

Question is this correct? And if so is there property I can query to figure out that the doc is not in fact being ‘saved’ (ShouldCallWriteDocument) on copy and also that BeginOpenDocument and EndOpenDocument are in fact not being triggered by new doc being opened?

(Menno Deij - van Rijswijk) #2

I encountered this similar problem as well. AFAIK there is no OnCopy or OnPaste event.
What I did in the end was to look at the Merge property of the DocumentOpenEventArgs. This is true if a Paste is performed and false if a document is opened. Unfortunately it is also true if the user gives and Import command, so you can’t distinguish between these two.

In fact, a document is really being saved. When copying, a 3dm file is written to a temporary location. It is imported/merged upon pasting.

Come to think of it - you maybe can also check the filename. If it is in %Appdata%\Temp it is probably a copied document.


Thanks menno, I’ll take a look at those EventArgs.


This issue seems to propagate through to the plugin class. Rhino.PlugIns.WriteDocument gets called if you copy an object into the clipboard, and Rhino.PlugIns.ReadDocument gets called if you paste from the clipboard. This has the potential to cause some issues if you are not aware of it. I /think/ for WriteDocument, options.IncludeHistory == false when copying. For ReadDocument, options.ImportMode == true for pasting - but other Rhino actions may trigger the same event args.

Given ReadDocument and WriteDocument are critical for loading/saving Rhino data robustly, perhaps the above could be refined by the developers?



encountered the same problem, maybe this can be addressed for V6?

(Dale Fugier) #6

Hi @atair,

Does your plug-in’s WriteDocument and ReadDocument members take file export and import into account? If so, then your code should be proper for CopyToClipboard/Paste.

– Dale


hello @dale,
not sure what you mean - my problem is not related to the Plugin class, but rather that the a ctrl-v paste fires a OpenDocument event.
For now i can distinguish it from a real ‘open document’ with the filename that starts with ‘rh$’ in case of a paste. While that works, it could be a problem if anyone decides to name their files rh$something.3dm

(Dale Fugier) #8

Hi @atair,

Sorry for my previous post - not sure what I was responding to…

A Paste operation is bascially the same as Import. Thus, DocumentOpenEventArgs.Merge will be set to true.

Does this help?

– Dale


@dale - yes that is what i was looking for - thanks!