Show / Hide Table of Contents

Body Properties

This example creates a solid box, and prints its properties in the logger (the output window in RobotStudio).

Example

Project.UndoContext.BeginUndoStep("BodyProperties");
try
{
    Station station = Station.ActiveStation;

    // Create a part to contain the bodies.
    Part p = new Part();
    p.Name = "My_Part";
    station.GraphicComponents.Add(p);

    // Create a solid box.
    Matrix4 matrix_origo = new Matrix4(new Vector3(Axis.X), 0.0);
    Vector3 size = new Vector3(0.5, 0.5, 0.5);
    Body b1 = Body.CreateSolidBox(matrix_origo, size);
    b1.Name = "Box";
    p.Bodies.Add(b1);

    // Log a summary of the bodies properties.
    Logger.AddMessage(new LogMessage($"The body '{b1.Name}' has the following properties:"));

    Logger.AddMessage(new LogMessage(
        $"Center of gravity: x: {b1.CenterOfGravity.x}, y: {b1.CenterOfGravity.y}, z: {b1.CenterOfGravity.z}"));

    Logger.AddMessage(new LogMessage($"Color: {b1.Color}"));

    Logger.AddMessage(new LogMessage($"Moment of Inertia: " +
        $"x: ({b1.MomentOfInertia.x.x}, {b1.MomentOfInertia.x.y}, {b1.MomentOfInertia.x.z}), " +
        $"y: ({b1.MomentOfInertia.y.x}, {b1.MomentOfInertia.y.y}, {b1.MomentOfInertia.y.z}), " +
        $"z: ({b1.MomentOfInertia.z.x}, {b1.MomentOfInertia.z.y}, {b1.MomentOfInertia.z.z})"));

    Logger.AddMessage(new LogMessage($"Has '{b1.Shells.Count}' number of shells."));
    Logger.AddMessage(new LogMessage($"Surface area: {b1.SurfaceArea}"));
    Logger.AddMessage(new LogMessage($"Transform: " +
        $"X: {b1.Transform.X}, Y: {b1.Transform.Y}, Z: {b1.Transform.Z}, " +
        $"Rx: {b1.Transform.RX}, Ry: {b1.Transform.RY}, Rz: {b1.Transform.RZ}"));

    Logger.AddMessage(new LogMessage($"Visibility: {b1.Visible}"));
    Logger.AddMessage(new LogMessage($"Volume: {b1.Volume}"));
}
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
  • Body
In this article
Back to top Copyright © 2025 ABB