Creating Targets using GraphicPicker
Graphic picker event enables user to get the clicked position information. This example provides information on creating targets at the clicked positions.
Use this procedure to create targets on pick position :
Initialize GraphicPick.
Click RobotStudio graphic window to raise the GraphicPick event.
Get PickedPosition from GraphicPickEventArgs to create RsTarget object instance.
Note
Uninitialize GraphicPicker event after the operation has been completed.
Example
This example provides information on picking targets graphically in RobotStudio.
public void PickTargets()
{
// Subscribe to the 'GraphicPick' event that triggers when the user picks objects in the graphics view
GraphicPicker.GraphicPick += (sender, e) =>
{
// Begin UndoStep
Project.UndoContext.BeginUndoStep("CreateTarget");
try
{
// Creates target at the picked position
CreateRobotStudioTarget(e.PickedPosition);
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
};
}
private static void CreateRobotStudioTarget(Vector3 position)
{
try
{
// Get the active station
Station station = Station.ActiveStation;
// Create a new robot target with a unique name
RsRobTarget robTarget = new RsRobTarget();
robTarget.Name = station.ActiveTask.GetValidRapidName("Target", "_", 10);
// Set the robot target's position
robTarget.Frame.Translation = position;
// Add robtarget to data declaration
station.ActiveTask.DataDeclarations.Add(robTarget);
// Create and configure the visual target representation
RsTarget target = new RsTarget(station.ActiveTask.ActiveWorkObject, robTarget);
target.Name = robTarget.Name;
target.Attributes.Add(target.Name, true);
// Add targets to active task
station.ActiveTask.Targets.Add(target);
}
catch (Exception ex)
{
ApplicationLogger.LogException(ex);
}
}
Required Namespaces
ABB.Robotics.RobotStudio.Stations.Forms
ABB.Robotics.RobotStudio.Stations
ABB.Robotics.RobotStudio.Diagnostics