The Alignment class represents a horizontal alignment in Civil3D, typically used for road centerlines, pipelines, or any linear feature. It can contain curves, lines, and spirals.
Autodesk.Civil.DatabaseServices
System.Object
└─ RXObject
└─ DBObject
└─ Entity
└─ Feature
└─ Alignment
| Property | Type | Description |
|---|---|---|
Name |
string |
Gets/sets the alignment name |
Description |
string |
Gets/sets the description |
Length |
double |
Gets the total length |
StartingStation |
double |
Gets/sets the starting station value |
EndingStation |
double |
Gets the ending station value |
SiteId |
ObjectId |
Gets/sets the parent site ObjectId |
StyleId |
ObjectId |
Gets/sets the alignment style |
Entities |
AlignmentEntityCollection |
Gets the collection of alignment entities |
| Method | Return Type | Description |
|---|---|---|
GetProfileViewIds() |
ObjectIdCollection |
Gets all profile view ObjectIds |
GetProfileIds() |
ObjectIdCollection |
Gets all profile ObjectIds |
StationOffset(double, double, out double, out double) |
void |
Converts XY to station/offset |
PointLocation(double, double) |
Point3d |
Gets XY from station/offset |
GetStationAtPoint(Point3d) |
double |
Gets station at a point |
using Autodesk.Civil.DatabaseServices;
using (Transaction tr = civilDoc.Database.TransactionManager.StartTransaction())
{
ObjectIdCollection alignmentIds = civilDoc.GetAlignmentIds();
if (alignmentIds.Count > 0)
{
Alignment alignment = tr.GetObject(alignmentIds[0], OpenMode.ForRead) as Alignment;
ed.WriteMessage($"\nAlignment: {alignment.Name}");
ed.WriteMessage($"\nLength: {alignment.Length:F2}");
ed.WriteMessage($"\nStart Station: {alignment.StartingStation:F2}");
ed.WriteMessage($"\nEnd Station: {alignment.EndingStation:F2}");
}
tr.Commit();
}using (Transaction tr = civilDoc.Database.TransactionManager.StartTransaction())
{
Alignment alignment = tr.GetObject(alignmentId, OpenMode.ForRead) as Alignment;
double station = 100.0;
double offset = 5.0; // 5 units to the right
Point3d point = alignment.PointLocation(station, offset);
ed.WriteMessage($"\nPoint at Station {station}, Offset {offset}:");
ed.WriteMessage($"\n X: {point.X:F2}, Y: {point.Y:F2}");
tr.Commit();
}using (Transaction tr = civilDoc.Database.TransactionManager.StartTransaction())
{
Alignment alignment = tr.GetObject(alignmentId, OpenMode.ForRead) as Alignment;
Point3d testPoint = new Point3d(1000, 2000, 0);
double station, offset;
alignment.StationOffset(testPoint.X, testPoint.Y, out station, out offset);
ed.WriteMessage($"\nPoint ({testPoint.X:F2}, {testPoint.Y:F2}):");
ed.WriteMessage($"\n Station: {station:F2}");
ed.WriteMessage($"\n Offset: {offset:F2}");
tr.Commit();
}using (Transaction tr = civilDoc.Database.TransactionManager.StartTransaction())
{
Alignment alignment = tr.GetObject(alignmentId, OpenMode.ForRead) as Alignment;
foreach (AlignmentEntity entity in alignment.Entities)
{
ed.WriteMessage($"\nEntity Type: {entity.EntityType}");
ed.WriteMessage($"\n Start Station: {entity.StartStation:F2}");
ed.WriteMessage($"\n End Station: {entity.EndStation:F2}");
ed.WriteMessage($"\n Length: {entity.Length:F2}");
if (entity.EntityType == AlignmentEntityType.Arc)
{
AlignmentArc arc = entity as AlignmentArc;
ed.WriteMessage($"\n Radius: {arc.Radius:F2}");
}
}
tr.Commit();
}using (Transaction tr = civilDoc.Database.TransactionManager.StartTransaction())
{
Alignment alignment = tr.GetObject(alignmentId, OpenMode.ForRead) as Alignment;
ObjectIdCollection profileIds = alignment.GetProfileIds();
ed.WriteMessage($"\nProfiles for alignment '{alignment.Name}':");
foreach (ObjectId profileId in profileIds)
{
Profile profile = tr.GetObject(profileId, OpenMode.ForRead) as Profile;
ed.WriteMessage($"\n {profile.Name}");
}
tr.Commit();
}- Profile - Vertical profile along alignment
- CivilDocument - Container for alignments
- Feature - Base class