Exception when calling ABB.Robotics.Controllers.RapidDomain.Task.SaveProgramToFile

First I check all Controllers:

foreach (ControllerObjectReference controllerReference in ControllerManager.ControllerReferences)

Then all the Tasks der Controller checked: (ABB.Robotics.Controllers.Controller)

var rapidTasks = controller.Rapid.GetTasks();

Then the Modules should be saved:

{

private readonly ABB.Robotics.Controllers.RapidDomain.Task_task;

string f = “d:\01_DATEN\03_Temp\” + _task.Name;

try

{

_task.SaveProgramToFile(f);

}

catch (Exception ex)

{

Logger.AddMessage("Problem saving file " + f + ex);

}

…..

}

The function “SaveProgramToFile” needs as argument the directory where the program will be saved. When using subdirectories, the definition for the path-separator is critical. In your case, you are using “\” and this will throw an error in RobotStudio (I did not test on a real machine).

See the following code for a working solution:


private void button1_Click(object sender, EventArgs e)
{
    //Declare Variables
    Controller RobotController = null;
    string filePath;

    try
    {
        //Get RobotController
        RobotController = new Controller();
        
        //Set directory
        filePath = RobotController.FileSystem.LocalDirectory + @"/files_backup";

        foreach (Task t in RobotController.Rapid.GetTasks())
        {
            // save to file
            t.SaveProgramToFile(filePath);

            // dispose
            t.Dispose();
        }
        GTPUMessageBox.Show(this, null, "Saved in " + filePath, null);
        
    }
    catch (Exception ex)
    {
        // Exception handling
        GTPUMessageBox.Show(this, null, "Error...\n" + ex.Message, null);
    }
    finally
    {
        // clean-up controller
        if (RobotController != null)
        {
            RobotController.Dispose();
            RobotController = null;
        }
    }
}