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 a target called Target_10. This is the target that you just created with your Addin. If you run the Add-In more than once, you will create Target_20, Target_30 and so on.
Use this procedure to create targets:
Get Station object
Create a new Rs
Rob and add it to ActiveTarget Task .Create an Rs
Target from wobj and RobTarget.Add RsTarget to ActiveTask.
Solution
Get Station Object
Station station = Project.ActiveProject as Station;
Create a new RsRobTarget and add it to ActiveTask.
RsRobTarget robTarget = new RsRobTarget(); robTarget.Name = station.ActiveTask.GetValidRapidName("Target", "_", 10); //translation robTarget.Frame.Translation = position; //add robtargets to datadeclaration station.ActiveTask.DataDeclarations.Add(robTarget);
Create an RsTarget from wobj and RobTarget.
RsTarget target = new RsTarget(station.ActiveTask.ActiveWorkObject, robTarget); target.Name = robTarget.Name; target.Attributes.Add(target.Name, true);
Add RsTarget to ActiveTask.
station.ActiveTask.Targets.Add(target);
Example
This example provides information on creating targets in RobotStudio.
private static void CreateTargets()
{
//Begin UndoStep
Project.UndoContext.BeginUndoStep("CreateTarget");
try
{
// Create the first robotstudio target.
ShowTarget(new Vector3(-0.50629, -3, 0.67950));
// Create the second robotstudio target.
ShowTarget(new Vector3(0.500, 0, 0.700));
}
catch (Exception exception)
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
Logger.AddMessage(new LogMessage(exception.Message.ToString()));
}
finally
{
//End UndoStep
Project.UndoContext.EndUndoStep();
}
}
private static void ShowTarget(Vector3 position)
{
try
{
//get the active station
Station station = Project.ActiveProject as Station;
//create robtarget
RsRobTarget robTarget = new RsRobTarget();
robTarget.Name = station.ActiveTask.GetValidRapidName("Target", "_", 10);
//translation
robTarget.Frame.Translation = position;
//add robtargets to datadeclaration
station.ActiveTask.DataDeclarations.Add(robTarget);
//create target
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 exception)
{
Logger.AddMessage(new LogMessage(exception.Message.ToString()));
}
}
Required Namespaces
ABB.
ABB.
ABB.