I would like to ask how can I enable undo in Rhino after I execute Rhino Command?
In the command I duplicate the mesh and modify it, then replace the input mesh with the modified one.
After the command line is executed and the mesh is replaced, Ctrl+Z does not do anything.
const ON_Mesh* RhinoMesh_ = go.Object(0).Mesh(); //Get Mesh
ON_Mesh RhinoMesh(*RhinoMesh_);//Copy Mesh
RhinoMesh_->~ON_Mesh();//Delete user input
CRhinoMeshObject* meshObjBaked = NULL;
CRhinoObjRef objRef = NULL;
// Do Something with it
////////////////////////////////////////////////////////////////
// Bake Mesh
////////////////////////////////////////////////////////////////
if (rhinoMesh.IsValid()) {
if (meshObjBaked == NULL) {
meshObjBaked = context.m_doc.AddMeshObject(rhinoMesh);
objRef = CRhinoObjRef(meshObjBaked);
}
else {
context.m_doc.ReplaceObject(objRef, rhinoMesh);
}
context.m_doc.Redraw();
}
I don’t think you should call the destructor on the input mesh, it is a const pointer, which indicates that it is “read-only”. I suspect that this may also break undo, as undo/redo should just work for modifications done by a command.