Show / Hide Table of Contents

Getting and Modifying Attachments

This example logs all the station's attachments to the output view.

Create two boxes and attach one of them to the other, and run the Add-In. The attachments will be shown in the logger (the output window in RobotStudio), together with the attached box transform. If you move the parent (the box that you attached the other box to) and run the Add-In again, you can see that the transform has changed.

Solution

  1. Get the active station.

    Station stn = Station.ActiveStation;
    
  2. Iterate through all the attachments in the active station and log their details.

    foreach (Attachment att in stn.Attachments)
    
    • Get the attachments transform values.

      string transStr = $"X: {att.Offset.t.x} Y: {att.Offset.t.y} Z: {att.Offset.t.z} " +
                        $"RX: {att.Offset.EulerZYX.x} RY: {att.Offset.EulerZYX.y} RZ: {att.Offset.EulerZYX.z}";
      
    • Output the AttachmentParent, the AttachmentChild and the transform.

      Logger.AddMessage(new LogMessage(
           $"Child: {att.AttachmentChild.Name} is attached to " +
           $"Parent: {att.AttachmentParent.Name} and has transform: {transStr}"));
      

Example

This example logs all the station's attachments to the output view.

Project.UndoContext.BeginUndoStep("Attachments Properties");
try
{
    // Instance active station.
    Station stn = Station.ActiveStation;

    // Enumerates the attachments in the station and outputs their info using the logger.
    Logger.AddMessage(new LogMessage("The station contains the following attachments:"));
    foreach (Attachment att in stn.Attachments)
    {
        // Get the attachments transform values.
        string transStr = $"X: {att.Offset.t.x} Y: {att.Offset.t.y} Z: {att.Offset.t.z} " +
                          $"RX: {att.Offset.EulerZYX.x} RY: {att.Offset.EulerZYX.y} RZ: {att.Offset.EulerZYX.z}";

        // Output the AttachmentParent, the AttachmentChild and the transform.  
        Logger.AddMessage(new LogMessage(
             $"Child: {att.AttachmentChild.Name} is attached to " +
             $"Parent: {att.AttachmentParent.Name} and has transform: {transStr}"));
    }
}
catch
{
    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
    throw;
}
finally
{
    Project.UndoContext.EndUndoStep();
}

Required Namespaces

ABB.Robotics.RobotStudio

ABB.Robotics.RobotStudio.Stations

See Also

  • Attachment
  • Modify Position
  • Modifying Local Origin
In this article
Back to top Copyright © 2025 ABB