Show / Hide Table of Contents

Modifying Position

This example provides information on moving and rotating a part relative to the work object's user frame (it could also be the object frame).

Make sure that you have a part in your station by either creating one or importing one. Select the part, either in the browser or the graphics view, and run your Add-In. This will move and rotate the part as defined in translationMatrix.

  1. Get the active station.

    Station station = Station.ActiveStation;
    
  2. Get the active RsWorkObject.

    RsWorkObject workObj = station.ActiveTask.ActiveWorkObject;
    
  3. Get the graphically selected part.

    Part selectedPart = Selection.SelectedObjects.SingleSelectedObject as Part;
    
  4. Check if a part is selected.

    if (selectedPart != null)
    
  5. Define how to move and rotate the selected part.

    Matrix4 translationMatrix = new Matrix4(new Vector3(1, 0, 0.5),
                                new Quaternion(Vector3.XVector, 0.5));
    
  6. Move the part relative to the user frame.

    selectedPart.Transform.SetRelativeTransform
             (workObj.UserFrame.GlobalMatrix, translationMatrix);
    

Example

This example provides information on moving and rotating a part relative the work object's user frame.

Project.UndoContext.BeginUndoStep("Move Part Relative Frame");
try
{
    // Get the active station.
    Station station = Station.ActiveStation;

    // Get the active work object.
    RsWorkObject workObj = station.ActiveTask.ActiveWorkObject;

    // Get the selected part.
    Part selectedPart = Selection.SelectedObjects.SingleSelectedObject as Part;

    // Check if there is a part selected.
    if (selectedPart != null)
    {
        // Define how we should move and rotate the selected part.
        Matrix4 translationMatrix = new Matrix4(new Vector3(1, 0, 0.5),
                                    new Quaternion(Vector3.XVector, 0.5));

        // Move the part relative the user frame.
        selectedPart.Transform.SetRelativeTransform
                 (workObj.UserFrame.GlobalMatrix, translationMatrix);
    }
}
catch
{
    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
    throw;
}
finally
{
    Project.UndoContext.EndUndoStep();
}

Required Namespaces

ABB.Robotics.RobotStudio

ABB.Robotics.RobotStudio.Stations

ABB.Robotics.Math

See Also

  • Part Information
  • Modifying Local Origin
In this article
Back to top Copyright © 2025 ABB