Using the OnLoad callback function
Add-Ins use the OnLoad() function that allows them to execute some code whenever the Add-In's .dll is loaded into RobotStudio.
Note
You can easily try out this example using the RobotStudio Empty Add-in template from Visual Studio.
Overriding OnLoad
Create a C# class that inherits from the HostedAddInBase class:
public class Class1 : HostedAddInBase { // The Add-In's contents will go here }Write an overriding method for the OnLoad() method. Use the following code snippet to display a message whenever the Add-In is loaded.
public class Class1 : HostedAddInBase { public override void OnLoad() { // This code will be executed when the assembly is loaded. Logger.AddMessage(new LogMessage("Hello: The Add-In has just been loaded!")); base.OnLoad(); } }
The complete code for this example is:
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;
namespace Powerpac
{
public class Class1 : HostedAddInBase
{
public override void OnLoad()
{
// This code will be executed when the assembly is loaded.
Logger.AddMessage(new LogMessage("Hello: The Add-In has just been loaded!"));
base.OnLoad();
}
}
}