---
title: Get the LabelSetId from Alignment class
description: "## Motivation Civil 3D offers API to create an Alignment via the `Alignment.Create` static method. Interestingly, even though it takes in a `LabelSetId` as a constructor parameter, but it doesn’t expose the parameter. Which is really unfortunate. ## The workaround…"
url: "https://civilwhiz.com/docs/get-the-labelsetid-from-alignment-class/"
updated: "2025-03-13"
category: API
---

# Get the LabelSetId from Alignment class

## Motivation

Civil 3D offers API to create an Alignment via the `Alignment.Create` static method. Interestingly, even though it takes in a `LabelSetId` as a constructor parameter, but it doesn’t expose the parameter. Which is really unfortunate.

## The workaround – extension method

So we need to write our own extension method for it. Based on [Norman Yuan’s](https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921) idea on [a forum post](https://forums.autodesk.com/t5/civil-3d-customization/labelsetid-not-available-in-alignment-class/m-p/13254179#M26879), here’s the implementation.

```csharp
  public static AlignmentLabelSetStyle GetLabelSet(this Alignment alignment,
      CivilDocument civilDoc, Transaction ts)
  {

      foreach (ObjectId labelGroupId in alignment.GetAlignmentLabelGroupIds())
      {
          var labelGroup = ts.GetObject<AlignmentLabelGroup>(labelGroupId);
          foreach (var alignmentLabelSetStyleId in civilDoc.Styles.LabelSetStyles.AlignmentLabelSetStyles)
          {
              var alignmentLabelSetStyle = ts.GetObject<AlignmentLabelSetStyle>(alignmentLabelSetStyleId);
              foreach (var labelSetItem in alignmentLabelSetStyle)
              {
                  if (labelSetItem.LabelStyleName == labelGroup.StyleName
                      && SameLabelType(labelSetItem.LabelStyleType, labelGroup.LabelType))
                  {
                      return alignmentLabelSetStyle;
                  }
              }

          }

      }

      return null;
  }

 //this is unfortunate but I haven't find a more elegant way to map the two different LabelType
  private static bool SameLabelType(LabelStyleType labelStyleType, LabelType labelType)
  {
      switch (labelType)
      {
          case LabelType.SurfaceContour:
              return labelStyleType == LabelStyleType.SurfaceContour;
          case LabelType.AlignmentMajorStation:
              return labelStyleType == LabelStyleType.AlignmentMajorStation;
          case LabelType.AlignmentMinorStation:
              return labelStyleType == LabelStyleType.AlignmentMinorStation;
          case LabelType.AlignmentGeometryPoint:
              return labelStyleType == LabelStyleType.AlignmentGeometryPoint;
          case LabelType.AlignmentProfileGeometryPoint:
              return labelStyleType == LabelStyleType.AlignmentProfileGeometryPoint;
          case LabelType.AlignmentStationEquation:
              return labelStyleType == LabelStyleType.AlignmentStationEquation;
          case LabelType.AlignmentDesignSpeed:
              return labelStyleType == LabelStyleType.AlignmentDesignSpeed;
          case LabelType.AlignmentSuperelevationCriticalPoints:
              return labelStyleType == LabelStyleType.AlignmentSuperelevationCriticalPoints;
          case LabelType.AlignmentStationOffset:
              return labelStyleType == LabelStyleType.AlignmentStationOffset;
          case LabelType.AlignmentCurve:
              return labelStyleType == LabelStyleType.AlignmentCurve;
          case LabelType.AlignmentSpiral:
              return labelStyleType == LabelStyleType.AlignmentSpiral;
          case LabelType.AlignmentTangentIntersection:
              return labelStyleType == LabelStyleType.AlignmentTangentIntersection;
          case LabelType.AlignmentPointOfIntersection:
              return labelStyleType == LabelStyleType.AlignmentPointOfIntersection;
          case LabelType.ProfileMajorStation:
              return labelStyleType == LabelStyleType.ProfileMajorStation;
          case LabelType.ProfileMinorStation:
              return labelStyleType == LabelStyleType.ProfileMinorStation;
          case LabelType.ProfileHorizontalGeometryPoint:
              return labelStyleType == LabelStyleType.ProfileHorizontalGeometryPoint;
          case LabelType.ProfileGradeBreaks:
              return labelStyleType == LabelStyleType.ProfileGradeBreaks;
          case LabelType.ProfileLine:
              return labelStyleType == LabelStyleType.ProfileLine;
          case LabelType.ProfileCrestCurve:
              return labelStyleType == LabelStyleType.ProfileCrestCurve;
          case LabelType.ProfileSagCurve:
              return labelStyleType == LabelStyleType.ProfileSagCurve;
          case LabelType.ProfileViewDepth:
              return labelStyleType == LabelStyleType.ProfileViewDepth;
          case LabelType.SectionViewOffsetElevation:
              return labelStyleType == LabelStyleType.SectionViewOffsetElevation;
          case LabelType.SectionMajorOffset:
              return labelStyleType == LabelStyleType.SectionMajorOffset;
          case LabelType.SectionMinorOffset:
              return labelStyleType == LabelStyleType.SectionMinorOffset;
          case LabelType.SectionGradeBreak:
              return labelStyleType == LabelStyleType.SectionGradeBreak;
          case LabelType.SectionSegment:
              return labelStyleType == LabelStyleType.SectionSegment;
          case LabelType.ViewFrame:
              return labelStyleType == LabelStyleType.ViewFrame;
          case LabelType.SectionCorridorPoint:
              return labelStyleType == LabelStyleType.SectionCorridorPoint;
          default:
              return false;
      }
  }
```

You can just call `alignment.GetLabelSet(civilDoc, ts).ObjectId` to get the `ObjectId` for the `LabelSetId`.

  [![](https://civilwhiz.com/wp-content/uploads/2025/02/someoneme.jpg)](https://civilwhiz.com/author/civilwhiz/)[Ngu Soon Hui](https://civilwhiz.com/author/civilwhiz/)

My passion is in [sharing knowledge](/about/) — Civil 3D or otherwise– with the world.

I’m also the [benevolent dictator for life](https://mes100.com/about-ngu-soon-hui/) at MES Innovation Sdn Bhd.
