Show / Hide Table of Contents

Saving Program

This example provides information on saving a RAPID program from the controller to a local drive. An active station is needed for this example.

Pass the location where the RAPID program should be saved as a parameter. To check the result of the Add-In, ensure that the file is present in the filepath specified.

Solution

  1. Get the active task.

    // Get active task  
    RsTask task = Station.ActiveStation.ActiveTask;
    
  2. Get the virtual controller object based on RsIrc5Controller's SystemID.

    // Get virtual controller instance based on rsIrc5Controller systemId
    Guid controllerId = new Guid(((RsIrc5Controller)task.Parent).SystemId);
    using (Controller controller = Controller.Connect(controllerId, ConnectionType.RobotStudio))
    
  3. Get the RAPID task from the controller and create a directory.

    // Get RAPID task  
    ABB.Robotics.Controllers.RapidDomain.Task rapidTask = controller.Rapid.GetTask(task.Name);
    
    Directory.CreateDirectory(filePath);
    
  4. Use the SaveProgramToFile method of the Task class to save the program to the specified file path.

    // Save program to file  
    rapidTask.SaveProgramToFile(filePath);
    

Example

This example provides information on saving a RAPID program from the controller on to the local drive.

private static bool SaveProgram(string filePath)
{
    try
    {
        // Get active task  
        RsTask task = Station.ActiveStation.ActiveTask;

        // Get virtual controller instance based on rsIrc5Controller systemId
        Guid controllerId = new Guid(((RsIrc5Controller)task.Parent).SystemId);
        using (Controller controller = Controller.Connect(controllerId, ConnectionType.RobotStudio))
        {
            // Get RAPID task  
            ABB.Robotics.Controllers.RapidDomain.Task rapidTask = controller.Rapid.GetTask(task.Name);

            Directory.CreateDirectory(filePath);

            // Save program to file  
            rapidTask.SaveProgramToFile(filePath);
        }
        return true;
    }
    catch
    {
        return false;
    }
}

Required Namespaces

System.IO

ABB.Robotics.RobotStudio

ABB.Robotics.RobotStudio.Stations

ABB.Robotics.Controllers

See Also

  • Loading Program
In this article
Back to top Copyright © 2025 ABB