How to create targets by using API?

Hi Johannes,I would like more information from you about creating targets in RS5.07 by using API.Because it's very useful in our work.Thanks.

Comments

  • Hi Chris,

    typically you would do something like this to create a target and add it to a path:



    Station stn = Project.ActiveProject as Station;


    RsTask task = stn.ActiveTask;

    // Create RsRobTarget

    RsRobTarget robTarget = new RsRobTarget();


    robTarget.Name = <name>

    robTarget.ModuleName = <module>
    robTarget.Frame.Matrix = <matrix>
    task.DataDeclarations.Add(robTarget);
    // Create Target

    RsWorkObject wobj = task.ActiveWorkObject;


    RsTarget target = new RsTarget(wobj, robTarget);
    target.Name = <name>
    task.Targets.Add(target)
    // Create RsMoveInstruction
    RsToolData tool = task.ActiveTool;


    RsProcessDefinition procDef = task.ActiveProcessDefinition;
    RsProcessTemplate procTempl = procDef.ActiveProcessTemplate;
    RsMoveInstruction moveInstr = new RsMoveInstruction(task, procDef.Name, procTempl.Name, procTempl.ActiveMotionType, wobj.Name, robTarget.Name, tool);
    // Add to path
    PathProcedure path = task.ActivePathProcedure;
    path.Instructions.Add(moveInstr);

    (Note that the ".ActiveXXX" properties correspond to the selections in the Elements toolbar. You can change these to whatever suits you.)

    regards,
    Johannes
    Johannes Weiman
    Software Engineer
    ABB Robotics
  • I will have a try,thanks.