Demo Request about RhinoObject.OnDuplicate method

Who ever used RhinoObject.OnDuplicate, and/or a custom class drived from RhinoObject
with its OnDuplicate(maybe OnTransform or other methods) overrided, I need some demo on it,
or tell me the Sample code can be used for reference, thank you

Hi @chen_manhong,

Here is a simple example.

TestChen.cs (1.6 KB)

– Dale

Thank you Dale, you always help me

I had tried the example, it works, but another problem appears.
I add a custom mesh to doc, save the document and re-open it. When I select the mesh_obj I added before, it act as a class instance of MeshObject Class, my problem is how to re-establish it to the class instance of TestChenMeshObject Class?
Only in this way can TestChenMeshObject.OnDuplicate make sense. Can you help me? thanks.

Hi @chen_manhong,

By design, Rhino will not save custom Rhino objects to the document. Instead, Rhino only save the base class from which your object inherits. In the case of the sample I posted, Rhino saves the MeshObject.

In order to round trip you need to save whatever data you store on your custom object as user data. In doing this, your data will be saved with the base object.

When Rhino opens the document, check to see if objects contain your custom object’s user data. If so, then replace the Rhino object with your custom object.

Hope this helps.

– Dale