[RhinoCommon] BeginUndoRecord and EndUndoRecord

Have searched shortly but can’t find info about these functions.
I can add a UInteger but how to call this undo?

How does the function work and how to apply it?

Cheers,

Jordy

Hi Jordy, you can find an example here.

c.

So:

def MyStuff():
    sn = scriptcontext.doc.BeginUndoRecord("My Stuff")
    pt = Rhino.Geometry.Point3d(0,0,0)
    scriptcontext.doc.Objects.AddPoint(pt)
    scriptcontext.doc.Views.Redraw()
    if (sn > 0):
        scriptcontext.doc.EndUndoRecord(sn)

So the last EndUndoRecords(sn) will undo the AddPoint?

No, it tells Rhino to stop recording undo information, eg. when your document is changed outside of a command.

can you show an example ?

c.

My true problem is is that I have a plugin where i sometimes use rhinoapp.runscript for commands. The commands sometimes do a lot of stuff. When the command is done and I want to Undo it I sometimes have to undo 4 times to get back to the point I started the command. So I hoped this BeginUndoRecord an EndUndoRecord could help me with this.

The example is pretty easy:

            doc.BeginUndoRecord(UInteger("description as string"))

function

            doc.EndUndoRecord(UInteger("undoRecordSerialNumber"))

So I can start an undo record. And end it but how do I call it? To undo this stuff in between?
Or be able too undo the whole command in one time.

sorry, no idea if it can be used that way at all, i never used runscript. @dale might be able to provide more help.

c.

The only time you should need to call BeginUndoRecord/EndUndoRecord is if you are modifying the document from outside of a running command. For example, a modeless dialog box or a tabbed dockbar that modifies geometry is a good example of this.

If your plug-in command is defined as a script runner, then a single undo record is created for any and all document modifications that occur in this command or in any command scripted using RhinoApp.RunScript.

For example, the operations of this command can be “undone” by a single Undo operation:

[
System.Runtime.InteropServices.Guid("e6617215-682d-46cb-86a8-e0733d88d0a3"),
Rhino.Commands.CommandStyle(Rhino.Commands.Style.ScriptRunner)
]
public class TestCommand : Command
{
  public TestCommand() {}

  public override string EnglishName { get { return "TestCommand"; } }

  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  {
    Rhino.RhinoApp.RunScript("_Line 5,5 10,10", true);
    Rhino.RhinoApp.RunScript("_Line 10,5 5,10", true);
    doc.Views.Redraw();
    return Result.Success;
  }
}

Hope this helps.

Oke thanks for all the responses. Is it possible that to undo is comming from that I maybe use my own command within other created commands? That is causes a chain reaction?