Show / Hide Table of Contents

Deleting Targets

This example provides information on deleting targets that are not being used in the station. You will need an active station for this example.

To check the result of the Add-In, ensure that there are some targets in the station that do not have any corresponding motion instructions. Executing this Add-In would remove these unused targets.

Solution

  1. Get Station object and the list of targets associated with the station's active task.

    Station station = Station.ActiveStation;
    var targets = station.ActiveTask.Targets.ToArray();
    
  2. Get referencing instructions of target

    // Get referencing instructions of target
    RsInstruction[] instructions = target.RobTarget.GetReferencingInstructions();
    
  3. Delete target if it is not referred to by any instruction

    // Check that the target is not referenced in any instructions
    if (instructions.Length == 0)
    {
        // Delete the target from data declarations
        station.ActiveTask.DataDeclarations.Remove(target.RobTarget);
        // Delete the target from the station
        station.ActiveTask.Targets.Remove(target);
    }
    

Example

This example provides information on deleting targets in RobotStudio.

// Begin UndoStep
Project.UndoContext.BeginUndoStep("DeleteTarget");
try
{
    Station station = Station.ActiveStation;
    var targets = station.ActiveTask.Targets.ToArray();

    foreach (RsTarget target in targets)
    {
        // Get referencing instructions of target
        RsInstruction[] instructions = target.RobTarget.GetReferencingInstructions();

        // Check that the target is not referenced in any instructions
        if (instructions.Length == 0)
        {
            // Delete the target from data declarations
            station.ActiveTask.DataDeclarations.Remove(target.RobTarget);
            // Delete the target from the station
            station.ActiveTask.Targets.Remove(target);
        }
    }
}
catch
{
    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
    throw;
}
finally
{
    Project.UndoContext.EndUndoStep();
}

Required Namespaces

ABB.Robotics.RobotStudio.Stations

See Also

  • Creating Targets
  • Target Properties
In this article
Back to top Copyright © 2025 ABB