UndoStep
As you might have seen, all examples in this document starts out with the line
Project.UndoContext.BeginUndoStep("Step name");
This lines is what makes RobotStudio able to undo what you have done in your Add-In.
This code is good to put in your AddinMain()
-method of your Add-In.
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();
}