Getting Process and Instruction Templates
This example provides information on getting a RsProcessTemplate in RobotStudio. It also shows how to retrieve an RsInstructionTemplate from the process template. To perform these operations, you need an active station, the names of the desired ProcessTemplate and ProcessDefinition, and the task from which the templates will be retrieved. To check the result of the Add-In, ensure that the ProcessTemplate is present in the RobotStudio template manager.
Solution
Getting ProcessTemplate:
Use the ProcessDefinitions property of the task instance to check if the desired processDefinitionName exists using the TryGetProcessDefinition(string, out RsProcessDefinition) method. If it does, retrieve the corresponding RsProcessDefinition.
// Check if the task contains the specified process definition if (task.ProcessDefinitions.TryGetProcessDefinition(processDefinitionName, out RsProcessDefinition definition))If the process definition is found, use the TryGetProcessTemplate(string, out RsProcessTemplate) method of the ProcessTemplates collection to check if it contains the specified processTemplateName. If it does, retrieve the corresponding RsProcessTemplate.
// If the process definition is found, check if it contains the specified process template if (definition.ProcessTemplates.TryGetProcessTemplate(processTemplateName, out RsProcessTemplate template)) { return template; }
Getting RsInstructionTemplate:
- If the RsProcessTemplate is successfully retrieved, use the GetTemplate(MotionType) method to obtain an RsInstructionTemplate with the specified MotionType (e.g., MotionType.Linear).
RsProcessTemplate processTemplate = GetRsProcessTemplate(Station.ActiveStation.ActiveTask, "SearchL", "Default"); if (processTemplate != null) { // Get Template of type Linear RsInstructionTemplate insTemplate = processTemplate.GetTemplate(MotionType.Linear); }
Example
This example provides information on getting the RsProcessTemplate.
private static RsProcessTemplate GetRsProcessTemplate
(RsTask task, string processDefinitionName, string processTemplateName)
{
// Check if the task contains the specified process definition
if (task.ProcessDefinitions.TryGetProcessDefinition(processDefinitionName, out RsProcessDefinition definition))
{
// If the process definition is found, check if it contains the specified process template
if (definition.ProcessTemplates.TryGetProcessTemplate(processTemplateName, out RsProcessTemplate template))
{
return template;
}
}
return null;
}
Required Namespaces
ABB.Robotics.RobotStudio.Stations