Show / Hide Table of Contents

GraphicComponentGroup Properties

This example creates a GraphicComponentGroup and three parts (two boxes and one cylinder). The first two parts (one box and one cylinder) is added to the GraphicComponentGroup. The last box is attached to the group.

See the Layout browser (in either Home or Modeling tab) too see the group. You can see that it contains one box and one cylinder, and that the last box is attached (the name is surrounded by < and >).

Example

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

    // Create the GraphicComponentGroup.
    GraphicComponentGroup myGCGroup = new GraphicComponentGroup();
    myGCGroup.Name = "myGCGroup";

    // Add the GraphicComponentGroup to the GraphicComponents of the station.
    station.GraphicComponents.Add(myGCGroup);

    // Create a part.
    Part myPart1 = new Part();
    myPart1.Name = "MyPart1";

    // Create a box and add it to myPart1.
    Body box = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0), new Vector3(0.4, 0.4, 0.4));
    box.Name = "MyBox";
    myPart1.Bodies.Add(box);

    // Add myPart1 to myGCGroup.
    myGCGroup.GraphicComponents.Add(myPart1);

    // Create another part.
    Part myPart2 = new Part();
    myPart2.Name = "MyPart2";

    // Create a cylinder and add it to myPart2.
    Matrix4 origin = new Matrix4(new Vector3(0.5, 0.5, 0.5), 0.0);
    Body myCylinder = Body.CreateSolidCylinder(origin, 0.2, 1);
    myCylinder.Name = "myCylinder";
    myPart2.Bodies.Add(myCylinder);

    // Add myPart1 to myGCGroup.
    myGCGroup.GraphicComponents.Add(myPart2);

    // Create a third part.
    Part myPart3 = new Part();
    myPart3.Name = "MyPart3";

    // Create a box and add it to myPart3.
    Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0), new Vector3(0.1, 0.1, 0.1));
    box2.Name = "MyBox_2";
    myPart3.Bodies.Add(box2);

    // Add myPart3 to the station.
    station.GraphicComponents.Add(myPart3);

    // Attach myPart3 to myGCGroup, mount it on top of the cylinder, using an offset matrix.
    if (myGCGroup.CanAttachChild(myPart3))
    {
        myGCGroup.Attach(myPart3, true, new Matrix4(new Vector3(0.0, 0.0, 1.0)));
    }
    else
    {
        Logger.AddMessage(new LogMessage("Could not attach myPart3 to myGCGroup"));
    }
}
catch
{
    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
    throw;
}
finally
{
    Project.UndoContext.EndUndoStep();
}

See Also

  • Part
  • Body
  • GraphicComponentGroup
In this article
Back to top Copyright © 2025 ABB