In AutoCAD Civil 3D .NET API Reference guide, you will notice SurfaceContourLabelGroup class has overloaded function Create() to create a new Surface Contour LabelGroup.
In this post, I will show you how to use SurfaceContourLabelGroup.Create(ObjectId surfaceId, Point2dCollection labelLinePoints ) and SurfaceContourLabelGroup.CreateMultipleAtInterval(
ObjectId surfaceId,
Point2d labelLineStartPoint,
Point2d labelLineEndPoint,
double interval)
When we use SurfaceContourLabelGroup.Create(ObjectId surfaceId, Point2dCollection labelLinePoints), we need to pass in surfaceId and labelLinePoints. One important point to note here - There must be at least 2 points to compose the label line.
Here is a C# .NET code snippet -
using (Transaction trans = db.TransactionManager.StartTransaction())
{
try
{
/// surfaceId // Type: ObjectId // The ObjectId of surface to which the label is attahed.
/// labelLinePoints // Type: Point2dCollection // The place in which the label is located.
/// There must be at least 2 points to compose the label line.
ObjectId surfaceContourGrpLblId = SurfaceContourLabelGroup.Create(surfaceId, labelLinePoints);
trans.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage("\n Exception message :" + ex.Message);
}
}
And the result you will see in Civil 3D -
In this example I have used SurfaceContourLabelGroup.CreateMultipleAtInterval(ObjectId surfaceId, Point2d labelLineStartPoint, Point2d labelLineEndPoint, double interval). One important point to note here - you need to use an appropriate double value for the interval based on your surface extends so that the interval is not too close nor too large.
Here is a C# .NET code snippet -
try
{
/// labelLineStartPoint // Type: Point2d // The start point of label line.
/// labelLineEndPoint // Type: Point2d // The end point of label line.
/// interval // Type: System.Double // The interval between the label groups along contours.
///
SurfaceContourLabelGroup.CreateMultipleAtInterval(surfaceId, labelLineStartPoint, labelLineEndPoint, 100.0);
trans.Commit();
}
And the result you will see in Civil 3D -
Hope this is useful to you!