Empty UndoRecord

Is there a simple way to empty the UndoRecord in Rhino? I have a command I’m creating for a plugin that needs to disable the ability to undo any previous actions. I cannot find anything in the Rhinocommon API. There is the UndoRecord class, but I do not know where I could obtain the active instance of it, if there is one.

– cs

Hi @csykes,

Try this:

using Rhino;
using Rhino.Commands;
using Rhino.Input;

namespace TestCs7
{
  [CommandStyle(Style.NotUndoable)]
  public class TestCSykes : Command
  {
    public override string EnglishName => "TestCSykes";

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var rc = RhinoGet.GetCircle(out var circle);
      if (rc == Result.Success)
      {
        doc.Objects.AddCircle(circle);
        doc.Views.Redraw();
      }
      return Result.Success;
    }
  }
}

– Dale

1 Like

And if you just want to prevent any undo then you want to use RhinoDoc.ClearUndoRecords Method. Note though that users are probably not going to like it if suddenly their undos are impossible.

To clear redo records you’d use RhinoDoc.ClearRedoRecords Method.

1 Like

Excellent answer, thanks Nathan!

Hey @Dale, thanks for the answer, I assume this means the command itself cannot be undone, but anything that happened before the command still can be? Are commands NotUndoable by default as you have to create your own custom Undo methods usually.

Correct.

Correct.

No, commands are un-doable by default.

– Dale

1 Like

Thanks for clarifying Dale!