Saving Program
This example provides information on saving RAPID program from the controller on to local drive.An active station for this example.
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.
Use this procedure to save the program:
Get virtual controller object based on RsIrc5Controller 's object SystemID.
Get Rapid Task object and Create directory.
Use SaveProgramToFile instance method of Task type to save the program.
Solution
Get Station object and active RsTask.
Station station = Project.ActiveProject as Station; RsTask task = station.ActiveTask;
Get virtual controller object based on RsIrc5Controller's object SystemID.
RsIrc5Controller rsIrc5Controller = (RsIrc5Controller)task.Parent; //Get virtual controller instance based on rsIrc5Controller 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(task.Name); Directory.CreateDirectory(filePath);
Use SaveProgramToFile instance method of Task type to save the program.
controllerTask.SaveProgramToFile(filePath);
Example
This example provides information on saving RAPID program from the controller on to local drive.
private static bool SaveProgram(string filePath, string programName)
{
bool result = false;
Project.UndoContext.BeginUndoStep("SaveProgram");
try
{
//Get Station object and task
Station station = Project.ActiveProject as Station;
RsTask task = station.ActiveTask;
RsIrc5Controller rsIrc5Controller = (RsIrc5Controller)task.Parent;
//Get virtual controller instance based on rsIrc5Controller systemId
ABB.Robotics.Controllers.Controller controller =
new Controllers.Controller(new Guid(rsIrc5Controller.SystemId.ToString()));
//Get Rapid Task
Task controllerTask = controller.Rapid.GetTask(task.Name);
Directory.CreateDirectory(filePath);
//Save Program
controllerTask.SaveProgramToFile(filePath);
result = true;
}
catch (ABB.Robotics.GeneralException gex)
{
Logger.AddMessage(new LogMessage(gex.Message.ToString()));
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
result = false;
}
catch (Exception ex)
{
Logger.AddMessage(new LogMessage(ex.Message.ToString()));
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
result = false;
}
finally
{
Project.UndoContext.EndUndoStep();
}
return result;
}
Required Namespaces
ABB.Robotics.RobotStudio.Environment
ABB.Robotics.Controllers.RapidDomain