We use a CustomMeshObject in our plug-ins. I have tried to add instances of this class with a HistoryRecord to the RhinoDoc, but have not succeeded in finding out how to do this.
Typically, we add the custom object like this:
Mesh m; // defined elsewhere
MyCustomMeshObject o = new MyCustomMeshObject(m);
doc.Objects.AddRhinoObject(o);
Guid g = o.Id;
But: RhinoDoc.AddRhinoObject has no signature that also supports adding a HistoryRecord.
I’ve tried the approach below, but replacing the mesh with the custom mesh object breaks the history immediately.
HistoryRecord h = new HistoryRecord(this, 1);
WriteHistory(h);
Guid g = doc.Objects.AddMesh(m, null, h, false);
RhinoObject obj = doc.Objects.Find(g);
MyCustomMeshObject o = new MyCustomMeshObject(obj.Geometry as Mesh);
doc.Objects.Replace(new ObjRef(obj), o); // this breaks the history defined above
@dale or @stevebaer, do you have any hints on how to support history with custom objects?
I am not seeing a way to add a HistoryRecord to a custom object. Clearly there should be an override to doc.AddRhinoObject where you could pass a HistoryRecord object.
I’ve addded this feature to the RhinoCommon wish list. If we ever make the list public, you can see your item here.
If this is going to be implemented in RhinoCommon, functionality for CustomObjects should also be added to ReplayHistory. Specifically to
replayData.Result[0].UpdateTo[...]
Currently, only standard geometry is allowed in the Update statements. So, even though I succeeded in setting a history record on my custom object by some excursion to C++ from C#, replay history is only capable to update as a mesh, not a custom mesh.
It would be nice to have this functionality in an upcoming SR, if possible.