Importing MoveInstruction
This example provides information on importing MoveInstruction based on process definition. You need an active station for this example.
Pass the filepath of process defintion. To check the result of the addin, ensure that the instruction can be created from RobotStudio.
Use this procedure to Import Move Instruction:
Get Station object and active RsTask.
Get Instruction name from filepath.
If instruction exists and is MoveInstruction then Import ProcessDefinition from filepath.
Solution
Get Station object and active RsTask.
Station stn = Project.ActiveProject as Station; RsTask task = stn.ActiveTask;
Get Instruction name from filepath.
const string cMoveInstruction = "MoveInstruction"; //Get instruction name from filepath string instrName = System.IO.Path.GetFileNameWithoutExtension(filePath);
If instruction exists and is MoveInstruction then Import RsProcessDefintion from filepath.
if (task.InstructionDescriptions.Contains(instrName.ToLower())) { if (task.InstructionDescriptions[instrName.ToLower()].ToString() == cMoveInstruction) { //Import ProcessDefinition from filePath if (ImportProcessDefinitionFile(filePath)) { result = true; } } }
Example
This example provides information on importing RsMoveInstruction based on process definition.
This example provides information on importing RsProcessDefinition.
private static bool ImportMoveInstruction(string filePath)
{
bool result = false;
Project.UndoContext.BeginUndoStep("ImportMoveInstruction");
try
{
//Get Station object and Task
Station stn = Project.ActiveProject as Station;
RsTask task = stn.ActiveTask;
const string cMoveInstruction = "MoveInstruction";
//Get instruction name from filepath
string instrName = System.IO.Path.GetFileNameWithoutExtension(filePath);
//If instruction exists and is MoveInstruction then Import RsProcessDefintion from filepath
if (task.InstructionDescriptions.Contains(instrName.ToLower()))
{
if (task.InstructionDescriptions[instrName.ToLower()].ToString() == cMoveInstruction)
{
//Import ProcessDefinition from filePath
if (ImportProcessDefinitionFile(filePath))
{
result = true;
}
}
}
}
catch (Exception ex)
{
Logger.AddMessage(new LogMessage(ex.Message.ToString()));
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
}
finally
{
Project.UndoContext.EndUndoStep();
}
return result;
}
private static bool ImportProcessDefinitionFile(string filePath)
{
TextReader textReader = null;
//Get Station object
Station station = Project.ActiveProject as Station;
try
{
//Read the file
textReader = new StreamReader(filePath);
XmlTextReader definitionFile = new XmlTextReader(textReader);
//Import Process Definition into task
station.ActiveTask.ImportProcessDefinitions(definitionFile);
textReader.Close();
return true;
}
catch
{
if (textReader != null)
textReader.Close();
return false;
}
}
Required Namespaces
ABB.Robotics.RobotStudio.Environment
ABB.Robotics.Controllers.RapidDomain