Show / Hide Table of Contents

Saving the Station's state

Add-Ins and other entities in RobotStudio can save the current state of the station in which they are running. The station can be saved into a .rsstn file and it can be used to later restore the state of the station by the user.

Note

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

Saving the current station

  1. There are three function calls associated to the Station element in RobotStudio. The first one, Save(), stores the current state on a predefined station file. In other words, for Save() to work, the station needs to be stored in a .rsstn file already, otherwise it throws an exception.

    Station station = Station.ActiveStation;
    try
    {
        station.Save();
    }
    catch (Exception ex)
    {
        ApplicationLogger.LogException(ex);
    }
    
  2. The SaveAs(string) method can be used in a similar fashion but it receives a parameter that has the path and filename of the .rsstn file where the station will be stored. The method might throw an exception if an attempt to save into a directory that the user has no access to is performed.

    Station station = Station.ActiveStation;
    try
    {
        // Replace filePath with the desired save location for the station.
        string filePath = Path.Combine(Path.GetTempPath(), "mystation.rsstn");
        station.SaveAs(filePath);
    }
    catch (UnauthorizedAccessException ex)
    {
        ApplicationLogger.LogException("Save station failed. Do you have permission to write to that directory?", ex);
    }
    catch (Exception ex)
    {
        ApplicationLogger.LogException(ex);
    }
    
  3. The SaveCopyAs(string, bool) method is very similar to the SaveAs(string) method, but it has an overload that allows the developer to pass a boolean that indicates whether or not all the geometries of the station should be saved (since this method should be used for saving a mere copy of an already existing and updated file).

    Station station = Station.ActiveStation;
    try
    {
        // Replace filePath with the desired save location for the station.
        string filePath = Path.Combine(Path.GetTempPath(), "mystation.rsstn");
        station.SaveCopyAs(filePath, removeGeometry: false);
    }
    catch (UnauthorizedAccessException ex)
    {
        ApplicationLogger.LogException("Save station failed. Do you have permission to write to that directory?", ex);
    }
    catch (Exception ex)
    {
        ApplicationLogger.LogException(ex);
    }
    

See Also

  • Add-In OnLoad callback
  • Add-In Save and Close callbacks
  • Add-In File Options
  • Activate/Deactivate callbacks
  • Unload Callback
  • Creating a RobotStudio Add-In
  • Creating an Add-In File
In this article
Back to top Copyright © 2025 ABB