Creating Targets
This example provides information on creating targets. The example creates two targets with unique names. Attributes are added to targets to maintain their uniqueness. You will need an active station for this example.
Run your Add-In and go to the Home tab, and choose the Paths and Targets browser. Go to Station Elements -> Default Task -> Workobjects and Targets -> wobj0 -> wobj0_of. You will find two targets called Target_10 and Target_20. These are the targets that you just created with your Add-In. If you run the Add-In more than once, you will create Target_30 and Target_40, and so on.
Solution
Get the station object
// Get the active station Station station = Station.ActiveStation;
Create a new Rs
Rob and add it to the ActiveTarget Task // 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 a Rs
Target from the active WorkObject and 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 RsTarget to ActiveTask
// Add targets to active task station.ActiveTask.Targets.Add(target);
Example
This example provides information on creating targets in RobotStudio.
// Begin UndoStep
Project.UndoContext.BeginUndoStep("CreateTarget");
try
{
// Create the first target
CreateRobotStudioTarget(new Vector3(-0.50629, -3, 0.67950));
// Create the second target
CreateRobotStudioTarget(new Vector3(0.500, 0, 0.700));
}
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.
ABB.