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
Get the active task.
// Get active task RsTask task = Station.ActiveStation.ActiveTask;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))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);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
ABB.Robotics.RobotStudio.Stations