Show / Hide Table of Contents

Creating RsWorkobject

This example provides information on creating a new work object.

The UserFrame is the parent to the ObjectFrame, meaning that the position and orientation of the ObjectFrame are defined relative to the UserFrame.

At the end of the example, the work object is set as the default work object of ActiveTask.

Solution

  1. Create a RsWorkobject.

    // Create a RsWorkObject.
    RsWorkObject myWobj = new RsWorkObject();
    
    // Get a valid RAPID name for the workobject and assign it.
    myWobj.Name = station.ActiveTask.GetValidRapidName("myWobj", "_", 1);
    
  2. Translate and rotate the object frame.

    // Translate the object frame.
    myWobj.ObjectFrame.X = 0.5;
    myWobj.ObjectFrame.Y = 0.5;
    myWobj.ObjectFrame.Z = 0.5;
    
    // Rotate the object frame (pi radians around each axis).
    myWobj.ObjectFrame.RX = System.Math.PI;
    myWobj.ObjectFrame.RY = System.Math.PI;
    myWobj.ObjectFrame.RZ = System.Math.PI;
    
  3. Add the work object and set it as active.

    // Add the wobj to the DataDeclarations of the ActiveTask.
    station.ActiveTask.DataDeclarations.Add(myWobj);
    
    // Set the wobj as the active workobject of the ActiveTask.
    station.ActiveTask.ActiveWorkObject =
        (RsWorkObject)station.ActiveTask.
        FindDataDeclarationFromModuleScope(myWobj.Name, myWobj.ModuleName);
    

Example

This examples provides information on creating a new work object.

private static void CreateRsWorkobject()
{
    Project.UndoContext.BeginUndoStep("RsWorkObjectExample");
    try
    {
        Station station = Station.ActiveStation;

        // Create a RsWorkObject.
        RsWorkObject myWobj = new RsWorkObject();

        // Get a valid RAPID name for the workobject and assign it.
        myWobj.Name = station.ActiveTask.GetValidRapidName("myWobj", "_", 1);

        // Set the frame size to twice the default size.
        myWobj.FrameSize = myWobj.FrameSize * 2;

        // Set the userframe to be a fixed coordinate system.
        myWobj.UserFrameProgrammed = true;

        // Translate the user frame.
        myWobj.UserFrame.X = 0.5;
        myWobj.UserFrame.Y = 0.2;
        myWobj.UserFrame.Z = 0.2;

        // Translate the object frame.
        myWobj.ObjectFrame.X = 0.5;
        myWobj.ObjectFrame.Y = 0.5;
        myWobj.ObjectFrame.Z = 0.5;

        // Rotate the object frame (pi radians around each axis).
        myWobj.ObjectFrame.RX = System.Math.PI;
        myWobj.ObjectFrame.RY = System.Math.PI;
        myWobj.ObjectFrame.RZ = System.Math.PI;

        // Display the wobj in the graphics.
        myWobj.Visible = true;

        // Display the name of the wobj in the graphics.
        myWobj.ShowName = true;

        // The wobj is not held by the robot.
        myWobj.RobotHold = false;

        // Add the wobj to the DataDeclarations of the ActiveTask.
        station.ActiveTask.DataDeclarations.Add(myWobj);

        // Set the wobj as the active workobject of the ActiveTask.
        station.ActiveTask.ActiveWorkObject =
            (RsWorkObject)station.ActiveTask.
            FindDataDeclarationFromModuleScope(myWobj.Name, myWobj.ModuleName);
    }
    catch
    {
        Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
        throw;
    }
    finally
    {
        Project.UndoContext.EndUndoStep();
    }
}

Required Namespaces

ABB.Robotics.RobotStudio

ABB.Robotics.RobotStudio.Stations

See Also

  • Creating RsMoveInstruction
  • Importing MoveInstruction
In this article
Back to top Copyright © 2025 ABB