Show / Hide Table of Contents

Face Properties

This example shows the different properties of the Face class. A box is created and we select one of its faces. This Face is colored yellow and some information about it is printed in the logger (the output window in RobotStudio).

Compiling the Code

Note

You need to add System.Drawing as a reference for this example to work!

Example

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

    // Create a box.
    Part myPart = new Part();
    myPart.Name = "MyPart";
    station.GraphicComponents.Add(myPart);
    Body box = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0), new Vector3(0.1, 0.1, 0.1));
    box.Name = "MyBox";
    myPart.Bodies.Add(box);

    // Get a face from the box.
    Face myFace = box.Shells[0].Faces[0];

    // Make sure the face is visible.
    myFace.Visible = true;

    // Make the the face yellow.
    myFace.Color = Color.Yellow;

    // Output the name of the body of the face.
    Logger.AddMessage(new LogMessage($"The body of the face is: {myFace.Body.Name}"));

    // Traverse the loops of the face and output the number of coedges each has.
    int i = 1;
    foreach (Loop l in myFace.Loops)
    {
        Logger.AddMessage(new LogMessage($"Loop number '{i}' has '{l.Coedges.Count}' coedges"));
        i++;
    }

    // Find the vertex closest to a point.
    Vector3 point = new Vector3(0.6, 0.6, 0.6);
    Vertex closestVert = myFace.FindClosestVertex(point);
    Logger.AddMessage(new LogMessage(
        $"The closest vertex to the point is: ({closestVert.Position.ToString(numDecimals: 8, separator: ", ")})"));

    // Create a surface circle.
    Matrix4 matrix_origo = new Matrix4(new Vector3(Axis.X), 0.0);
    Body circle = Body.CreateSurfaceCircle(matrix_origo, 0.5);
    circle.Name = "Surface circle";
    myPart.Bodies.Add(circle);

    if (circle.Shells[0].Faces[0].ReverseNormal())
    {
        Logger.AddMessage(new LogMessage("Face of surface circle succesfully reversed!"));
    }
    else
    {
        Logger.AddMessage(new LogMessage("Reversal of face of surface circle failed!"));
    }
}
catch
{
    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
    throw;
}
finally
{
    Project.UndoContext.EndUndoStep();
}

See Also

  • Part
  • Body
  • Face
  • Coedge
  • Vertex
In this article
Back to top Copyright © 2025 ABB