Show / Hide Table of Contents

UndoStep

As you might have seen, all examples in this document starts out with the line:

Project.UndoContext.BeginUndoStep("Step name");

The BeginUndoStep() method marks the initiation of an undo step within your code. This action should be complemented by either an EndUndoStep() or a CancelUndoStep() method call. By doing so, any modifications made within this delimited scope can be reversed, allowing for a controlled undo functionality. It is also good to have try-catch-finally blocks in your code, in case something goes wrong.

Example

// This is where you start the undo step. Everything that is done between this line
// and the last line will be undone when you make Undo in RobotStudio.
Project.UndoContext.BeginUndoStep("The undo step");

try
{
    // This is where you write your Add-In code.
}

catch
{
    // This is where you write the code that should execute if something goes wrong
    // (i.e. if your code throws an exception).

    //This line cancels the undo step you started before.
    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
    throw;
}

finally
{
    // This is the end line of the undo step.
    Project.UndoContext.EndUndoStep();
}

See Also

  • UndoContext
  • CancelUndoStepType
In this article
Back to top Copyright © 2025 ABB