Export Program
This tutorial describes how to export RAPID program from the controller on to local drive.You will need an active Station for this tutorial.
You need to pass the location where the RAPID program gets exported or saved.To check the result of the addin, ensure that the file is present in the filepath specified.
Export RAPID program by following these steps:
Get RsIrc5Controller Instance.
Get virtual controller object based on RsIrc5Controller's object SystemId .
Get Rapid Task object and Create directory.
Call SaveProgramToFile function of rapid Task passing the directory created in step3 as a parameter.
Solution
Get RsIrc5Controller Instance.
Station station = Project.ActiveProject as Station; RsTask rsTask = station.ActiveTask; RsIrc5Controller rsIrc5Controller = (RsIrc5Controller)rsTask.Parent;Get virtual controller object based on RsIrc5Controller's object SystemID.
ABB.Robotics.Controllers.Controller controller = new Controllers.Controller(new Guid(rsIrc5Controller.SystemId.ToString()));Get Rapid Task object and Create directory.
Task controllerTask = controller.Rapid.GetTask(rsTask.Name); //Create Directory if it doesnot exist Directory.CreateDirectory(filePath);Call SaveProgramToFile function of rapid Task passing the directory created in step3 as a parameter.
controllerTask.SaveProgramToFile(filePath);
Example
This example shows how to export RAPID program from the controller on to local drive.
private static bool ExportRAPIDProgram(string filePath)
{
bool result = false;
try
{
//Get RsIrc5Controller instance
Station station = Project.ActiveProject as Station;
RsTask rsTask = station.ActiveTask;
RsIrc5Controller rsIrc5Controller = (RsIrc5Controller)rsTask.Parent;
//Get Controller object based on SystemID
ABB.Robotics.Controllers.Controller controller =
new Controllers.Controller(new Guid(rsIrc5Controller.SystemId.ToString()));
//Get Rapid Task
Task controllerTask = controller.Rapid.GetTask(rsTask.Name);
//Create Directory if it doesnot exist
Directory.CreateDirectory(filePath);
//Export Program
controllerTask.SaveProgramToFile(filePath);
result = true;
}
catch (ABB.Robotics.GeneralException)
{
result = false;
}
catch (Exception)
{
result = false;
}
return result;
}
Required Namespaces
ABB.Robotics.RobotStudio.Environment
ABB.Robotics.Controllers.RapidDomain