Unload callback
RobotStudio provides event handlers that the developer can implement on an Add-In so that it calls a function whenever the current project or station is closed. This can be used in many useful scenarios, for example, to save any current context for the user, unload certain external components, etc.
Note
You can easily try out this example using the RobotStudio Empty Add-in template from Visual Studio.
The Unload callback function
Create an Add-In using Visual Studio. In the main class of the Add-In, create the following callback function:
public class Class1:HostedAddInBase { public static void unloadCallback(object o, EventArgs e) { Logger.AddMessage(new LogMessage("The project is being unloaded")); } }We will tie the callback function to the unload event when the Add-In is loaded, therefore we will write that in the OnLoad() function.
public class Class1:HostedAddInBase { public static void unloadCallback(object o, EventArgs e) { Logger.AddMessage(new LogMessage("The project is about to be unloaded!")); } public override void OnLoad() { Project.ActiveProject.Closed += new EventHandler(unloadCallback); base.OnLoad(); } }
The complete code of the Add-In is shown below:
using System;
using System.Collections.Generic;
using System.Text;
using ABB.Robotics.Math;
using ABB.Robotics.RobotStudio;
using ABB.Robotics.RobotStudio.Environment;
using ABB.Robotics.RobotStudio.Stations;
using System.Diagnostics;
namespace Powerpac
{
public class Class1:HostedAddInBase
{
public static void unloadCallback(object o, EventArgs e)
{
Logger.AddMessage(new LogMessage("The project is about to be unloaded!"));
}
public override void OnLoad()
{
Project.ActiveProject.Closed += new EventHandler(unloadCallback);
base.OnLoad();
}
public void AddinMain()
{
// the code to execute goes here...
}
}
}