Dealing with UndoRecords

I am having trouble making Undo work properly. Let me first give a simplified explanation of what I am working on. I have blocks which I edit through an “EditMode” which is just a new DetailView.

This is my current structure;

  1. Start EditMode
  2. Temporary geometry baked.
  3. Geometry transformed and transforms stored.
  4. Begin my custom UndoRecord - method
  5. Final method to apply all transforms at once to block.
  6. End UndoRecord
  7. Purge all Temp Geometries

So I should be able to Undo the changes done through the final method, but the other changes while in the edit mode should not be in the UndoRecords.

With this, I can make the required undo work, but the Undos for the temporary geometry, which I purged, also works. The temporary geometry is recreated on Undo. This is my code, boiled down to the basics, in which I am also trying to clear the UndoRecords for the temporary geometries. But, in this case there is no Undo at all after.

class SampleCode
    private List<uint> TempUndo { get; set; } = new List<uint>();
    private uint MainUndo { get; set; }
    private RhinoDoc doc = RhinoDoc.ActiveDoc;
    private List<Guid> Geometry { get; set; }
    private bool update;
    public SampleCode()
        RhinoApp.Idle += OnRhinoIdle;
        Geometry = BakeTemporaryGeometry();

    private void ModifyBlock()
        // Modifies block with stored transforms of temporary geometry
        MainUndo = RhinoDoc.ActiveDoc.BeginUndoRecord("Edits");
        update = true;

    private void OnRhinoIdle(object sender, EventArgs e)
        var uRecNo = doc.NextUndoRecordSerialNumber - 1;
        if (!TempUndo.Contains(uRecNo) && uRecNo != MainUndo)

        if (update)
            update = false;

            foreach (var no in TempUndo)
                doc.ClearUndoRecords(no, true);
            foreach (Guid guid in Geometry)

Sorry for the long post. Any help is appreciated !

Hi @bovasbenjacob,

The Purge function will return false if the object being purge is part of an instance definition. You might check to see if this is the case.

– Dale

Hi Dale,
Thank you for the suggestion! I checked, and Purge returns true every time. Also, the geometries are not part of Instance Definitions. I further tested with a Rhino Object and the Purged object was added to the document again on Undo. Is this a bug or am I misunderstanding this?