UserData OnDuplicate not being called when copy paste is used?

I am working with custom user data on Rhino Objects. I am able to handle updating needed fields when the OnDuplicate method is called when the user issues a copy command. It seems however that this method is not called if a user uses the short cut copy paste on an object?

Any clarification would be helpful.

Joel

Hi Joel,

Rhino’s CopyToClipboard/Paste feature is really a file IO operation (e.g. Export, Import). Thus, you should expect your user data object’s UserData.Write and UserData.Read overrides to be called, if your user data support serialization.

Does this help?

– Dale

yes I noticed that the plugin went into read mode… okay I should be able to work with this.

thanks Dale.

is there a way to grab the objects being merged in the OnEndOpenDocument eventhandler? this way I can catch my objects that have been copied?

scratch that. it all makes sense now. I have a state on my data to let me know if it is current, loading, or copied. Handles perfectly now and pastes into a fresh rhino file as expected.

One more question here.

My write method hits a database and it does so once for every object I am tracking. Is there a way to bundle all of this on the rhino side so I can place this into a transaction for everything at once?

Thanks again,

Joel

Hi Joel,

I believe the best way to handle stuff like this is to set a flag when an interesting event occurs, such as your data is copied or pasted. Then, when Rhino’s RhinoApp.Idle event is triggered, check the flag and, if dirty, do what it takes to reset the flag (such as hit your database).

Does this help?

– Dale

this is exactly what is happening during a running session however when the file is written to .3dm the data is serialized using the RhinoCommon Binary Archive Writer.

I would still like to write the table entry to file on the rhino object but not have to call the database one at a time.

Hi Joel,

You know when Rhino is saving, by way of event watchers. So you could allow Rhino to save and then when it goes idle then hit your database.

A somewhat more drastic approach is to not store your data on each object, but rather to maintain a central table somewhere (probably on your plug-in object). Then save this data as document data in the 3dm file, which would save all of your data and hit your database all at one time. My user data sample demonstrates this.

– Dale

Understood.

Thank you,

Joel

Could you give the solution ?

Could you be more specific?

having the solution to manage the shortucut copy-paste so it copy the objects with the UserDatas. Is it possible?

Have you read this entire thread? The question (above) seems to be answered…

Hi @dale, Alt + Gumball drag (duplicate) on an object seems doing something different than CopyToClipboard/Paste.

CopyToClipboard/Paste triggers EndopenDocument event, from which I could identify if object is copy/pasted.

Is there anyway to capture this object duplication from Alt + Gumball drag?

Thanks in advance.
Mingbo

I think I have fount it. RhinoDoc.BeforeTransformObjects is will catch this Alt + Gumball drag action. @dale please let me know if I need to be aware of anything when dealing with these different types of copy/paste actions.

Hi @mingo1214,

Gumball dragging is a transformation operation and does not involved the Windows Clipboard.

– Dale

1 Like

Hi @dale, what is the best way to get duplicated objects by Alt + Gumball drag ?

Currently I have some code to check duplicated objects in RhinoDoc.SelectObjects, but now I’d like to move this out.
Is there any event that I can subscribe after RhinoDoc.BeforeTransformObjects but before RhinoDoc.SelectObjects ?

Hi @mingo1214,

Using SampleCsEventWatcher, I see this:

> BeginCommand (Drag)
Press Control to extrude, tap Alt to make a duplicate
> OnBeforeTransformObjects
> AddRhinoObject (3603b77d-a4ab-4835-b92d-2763e41e2e23)
> OnSelectObjects
> OnDeselectObjects
> EndCommand (Drag)

Does this help?

– Dale

Thanks @dale, this order is really helpful. So it is confirmed that there is nothing that I can do between AddRhinoObject() and OnSelectObjects(), right?