In AutoCAD Civil 3D, we can create different types of Labels for a Civil 3D Surface object. In the screenshot below, we can see from Annotation Tab, using the Add Labels, we can add a spot Elevation Label, Contour Label etc. for a Surface object.
Civil 3D .NET API has equivalent functions for creating Labels programmatically for many of these options as shown in the above screenshot.
If you want to create Surface Spot Elevation Label or Contour Label, you can use the following API -
SurfaceElevationLabel.Create()
SurfaceContourLabelGroup.Create()
In this C# .NET code snippet below, we can see how to create TIN surface spot elevation -
//select a surface
PromptEntityOptions selSurface = new PromptEntityOptions("\nSelect a Tin Surface: ");
selSurface.SetRejectMessage("\nOnly Tin Surface is allowed");
selSurface.AddAllowedClass(typeof(TinSurface), true);
PromptEntityResult resSurface = ed.GetEntity(selSurface);
if (resSurface.Status != PromptStatus.OK) return;
ObjectId surfaceId = resSurface.ObjectId;
//select a Point to Add Elevation Label
PromptPointOptions ppo = new PromptPointOptions("\nSelect a Point to Add Spot Elevation Label: ");
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK) return;
// Prepare the Elevation
double x = ppr.Value.X;
double y = ppr.Value.Y;
Point2d pnt2d = new Point2d(x, y);
Database db = Application.DocumentManager.MdiActiveDocument.Database;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
try
{
// create the spot elevation using SurfaceElevationLabel.Create
ObjectId surfaceElevnLblId = SurfaceElevationLabel.Create(surfaceId, pnt2d);
SurfaceElevationLabel label = surfaceElevnLblId.GetObject(OpenMode.ForRead) as SurfaceElevationLabel;
ed.WriteMessage("\nSurface Spot Elevation Label created and Style Name is :" + label.StyleName.ToString());
trans.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage("\n Exception message :" + ex.Message);
}
}
And here is the result -
Hope this is useful to you!