Search Results for

    Show / Hide Table of Contents

    Transforming Target

    This example provides information on reassociating targets with respect to another workobject without repositioning. It assumes that the targets have already been created and that a workobject (referred to here as newWorkObject) exists within your RobotStudio project. To follow this tutorial, you should pass instances of RsTargetCollection and RsWorkObject to the provided code. After executing the example code, the targets will be associated with the specified new work object (newWorkObject).

    Solution

    1. Get global matrix of newWorkobject.

      // Get global matrix of newWorkobject
      Matrix4 woObjectFrameGlobalMatrix = newWorkObject.ObjectFrame.GlobalMatrix;
      
    2. Inverse the global matrix of newWorkobject.

      // Inverse the global matrix
      woObjectFrameGlobalMatrix.InvertRigid();
      
    3. Get target frame global matrix.

      // Get the target's global matrix
      Matrix4 targetFrameMatrix = target.RobTarget.Frame.GlobalMatrix;
      
    4. Get new matrix value for target with respect to newWorkobject.

      // Get new matrix value for target with respect to newWorkobject
      Matrix4 finalMatrix = woObjectFrameGlobalMatrix * targetFrameMatrix;
      
    5. Change the workobject of target.

      // Change the workobject of target
      target.WorkObject = newWorkObject;
      
    6. Assign final matrix to target local matrix.

      // Update the RobTarget's frame with finalMatrix for new 3D position and orientation
      target.RobTarget.Frame.Matrix = finalMatrix;
      

    Example

    This example provides information on reassociating targets with respect to another workobject without repositioning.

    private static void TransformTargetBasedOnNewWorkObject(RsTargetCollection targets, RsWorkObject newWorkObject)
    {
        // Begin UndoStep
        Project.UndoContext.BeginUndoStep("ChangeWobj");
    
        try
        {
            // Iterate through each target in the collection to update their workobject
            foreach (RsTarget target in targets)
            {
                // Skip the update process if the target's current workobject matches the new workobject
                if (!target.WorkObject.Equals(newWorkObject))
                {
                    // Get global matrix of newWorkobject
                    Matrix4 woObjectFrameGlobalMatrix = newWorkObject.ObjectFrame.GlobalMatrix;
    
                    // Inverse the global matrix
                    woObjectFrameGlobalMatrix.InvertRigid();
    
                    // Get the target's global matrix
                    Matrix4 targetFrameMatrix = target.RobTarget.Frame.GlobalMatrix;
    
                    // Get new matrix value for target with respect to newWorkobject
                    Matrix4 finalMatrix = woObjectFrameGlobalMatrix * targetFrameMatrix;
    
                    // Change the workobject of target
                    target.WorkObject = newWorkObject;
    
                    // Update the RobTarget's frame with finalMatrix for new 3D position and orientation
                    target.RobTarget.Frame.Matrix = finalMatrix;
                }
            }
        }
        catch
        {
            Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
            throw;
        }
        finally
        {
            Project.UndoContext.EndUndoStep();
        }
    }
    

    Required Namespaces

    ABB.Robotics.Math

    ABB.Robotics.RobotStudio.Stations

    See Also

    • Transforming GraphicComponent
    In this article
    Back to top Copyright © 2026 ABB Robotics