Search Results for

    Show / Hide Table of Contents

    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

    1. Get the station object

      // Get the active station
      Station station = Station.ActiveStation;
      
    2. Create a new RsRobTarget and add it to the ActiveTask

      // 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);
      
    3. Create a RsTarget 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);
      
    4. 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.Robotics.RobotStudio.Stations

    ABB.Robotics.Math

    ABB.Robotics.RobotStudio.Diagnostics

    See Also

    • Target Properties
    • Deleting Targets
    In this article
    Back to top Copyright © 2026 ABB Robotics