Change Alignment Curve Label style using Civil 3D .NET API

By Partha Sarkar

Do you want to change the Label style of an Alignment curve element using Civil 3D .NET AP ? Here is the C# code snippet which demonstrates how to do this :

public void ChangeAlignmentCurveLblStyle()
{
 
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    PromptEntityOptions pops = new PromptEntityOptions("Select Alignment Curve Label : ");
    pops.AllowNone = true;
    PromptEntityResult pres = ed.GetEntity(pops);
    if (pres.Status != PromptStatus.OK)
        return;
    using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
    {
        try
        {
            AlignmentCurveLabel alignCurveLbl = (AlignmentCurveLabel)tr.GetObject(pres.ObjectId, OpenMode.ForWrite);
            ed.WriteMessage("nAlignment Curve Label Style Name (before Change) : " + alignCurveLbl.StyleName.ToString());
            // The following Style Name is specific to Tutorial DWG file - "Labels-6a.dwg"
            alignCurveLbl.StyleName = "Design Data";
            ed.WriteMessage("nAlignment Curve Label Style Name (after Change) : " + alignCurveLbl.StyleName.ToString());
            tr.Commit();
        }
        catch (System.Exception e)
        {
            System.Windows.Forms.MessageBox.Show(e.Message);
        }
 
    }
}


After executing the command in AutoCAD Civil 3D you will see a result similar to the screenshot below – 

C3D_Alignment_CurveLbl


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading