Search Results for

    Show / Hide Table of Contents

    Save and Close Station callbacks

    Learn more about the events fired when a station is saved and closed.

    Note

    You can easily try out this example using the RobotStudio Empty Add-in template from Visual Studio.

    Using the Save and Close callback functions

    1. Starting with a Class that contains the AddinMain method that serves as the entry point for the Add-In, we add a callback function that will execute when RobotStudio is about to save the project and we add a Handler for that function in the AddinMain:

      public class Class1 
      {
          public static void BeforeSaveCallback(object o, EventArgs e) 
          {
              Logger.AddMessage(new LogMessage("About to save the station..."));
          }
      
          public static void AddinMain() 
          {
              Station.ActiveStation.Saving += new SavingProjectEventHandler(BeforeSaveCallback);
              // The code that the Add-In will execute goes here.
          }
      }
      

      Note that the handler is created as an instance of SavingProjectEventHandler .

    2. We add another callback function, this time one that gets called by the event RobotStudio issues once a project has already been saved. Once more, we declare a handler and bind it to the event.

      public class Class1 
      {
          public static void BeforeSaveCallback(object o, EventArgs e) 
          {
              Logger.AddMessage(new LogMessage("About to save the station..."));
          }
      
          public static void AfterSaveCallback(object o, EventArgs e) 
          {
              Logger.AddMessage(new LogMessage("Station saved!"));
          }
      
          public static void AddinMain() 
          {
              Station.ActiveStation.Saving += new SavingProjectEventHandler(BeforeSaveCallback);
              Station.ActiveStation.Saved += new EventHandler(AfterSaveCallback);
              // The code that the Add-In will execute goes here.
          }
      }
      

      Note that, while the last handler was an instance of SavingProjectEventHandler , this handler is an instance of <xref:System.EventHandler> which is part of the standard <xref:System> C# namespace.

    3. Finally, we can add a callback function that executes when RobotStudio issues an event because of a closed project. The handle has the same built-in type and the binding is done in the same way:

      public class Class1 
      {
          public static void BeforeSaveCallback(object o, EventArgs e) 
          {
              Logger.AddMessage(new LogMessage("About to save the station..."));
          }
      
          public static void AfterSaveCallback(object o, EventArgs e) 
          {
              Logger.AddMessage(new LogMessage("Station saved!"));
          }
      
          public static void CloseCallback(object o, EventArgs e) 
          {
              Logger.AddMessage(new LogMessage("The project is about to be unloaded!"));
          }
      
          public static void AddinMain() 
          {
              Station.ActiveStation.Saving += new SavingProjectEventHandler(BeforeSaveCallback);
              Station.ActiveStation.Saved += new EventHandler(AfterSaveCallback);
              Project.ActiveProject.Closed += new EventHandler(CloseCallback);
              // The code that the Add-In will execute goes here.
          }
      }
      

      When this Add-In is loaded, saving the project will trigger the first two callbacks and closing it will trigger the third one. The output can be seen on RobotStudio's logger.

    See Also

    • Add-In OnLoad callback
    • Managing Options
    • Activate/Deactivate callbacks
    • Unload Callback
    • Creating a RobotStudio Add-In
    • Creating an Add-In File
    In this article
    Back to top Copyright © 2026 ABB Robotics