CustomMeshObject: read/write to RhinoDoc?


(Menno Deij - van Rijswijk) #1

I’m experimenting a bit with CustomMeshObject in RhinoCommon. I’m wondering a bit on its use when saving a document, and later re-opening it. So far, I haven’t succeeded in re-opening the CustomMeshObject - when the document gets re-opened, it is just a regular mesh.

Any hints on how to get this done? I could try to add some metadata to the mesh’s UserDictionary and upon re-opening a file try to convert all meshes back to CustomMeshObjects based on the presence of this metadata. Is that a good idea? Any problems to be expected?

Thanks for your insight!


(Steve Baer) #2

Converting to a custom object based on some known information in your plug-in is the typical route to go. Save the Guids of the custom mesh objects when your plug-in’s WriteDocument is called. This way your plug-in will be loaded when it Rhino encounters a file with your plug-in’s data written in it. Then you’ll have to replace the regular mesh objects that you’ve “customized” in the document.


(Menno Deij - van Rijswijk) #3

Ok, I will try this. Thanks for your suggestion!


(Menno Deij - van Rijswijk) #4

This method worked pretty good, until I noticed today that copying a CustomMeshObject and pasting it back did not work. During the Copy operation, the source Guid was written to the file and during pasting the source CustomMeshObject was replaced, and not the pasted mesh, because the pasted mesh has a different Guid after pasting.

So, I solved it differently by only writing a boolean to the file to tell if there are CustomMeshObjects present. Then, upon reading from the file data in the Mesh’ UserDictionary is used to re-create the CustomMeshObject. This then also works for copy/paste.