Show / Hide Table of Contents

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:

  1. Get Station object and active RsTask.

  2. Get Instruction name from filepath.

  3. If instruction exists and is MoveInstruction then Import ProcessDefinition from filepath.

Solution

  1. Get Station object and active RsTask.

    Station stn = Project.ActiveProject as Station;
    RsTask task = stn.ActiveTask;
    
  2. Get Instruction name from filepath.

    const string cMoveInstruction = "MoveInstruction";
    
    //Get instruction name from filepath
    string instrName = System.IO.Path.GetFileNameWithoutExtension(filePath);
    
  3. 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

See Also

  • Importing ActionInstruction
  • Importing ProcessDefinition
  • Getting Process and Instruction Templates
In this article
Back to top Copyright © 2025 ABB