Civil 3D FeatureLine Labeling and Style changing through .NET API

By Partha Sarkar

If you are
looking for an API to change AutoCAD Civil 3D FeatureLine object's style you
can use FeatureLine.StyleName property which gets or sets the Featureline's
style name. 

And using
Autodesk.Civil.DatabaseServices.GeneralSegmentLabel.Create() method we can add
Label to a FeatureLine. 

In the
screenshot below we can see a Civil 3D FeatureLine before changing it's style –

 

Civil3D_FeatureLine_Style

 

And using the
following C# .NET code we can change the style and label it –

 

using (Transaction ts = AcadApp.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
{
  FeatureLine featureLine = ts.GetObject(ftrLineID, OpenMode.ForWrite) as FeatureLine;
 
  // Change the Style to "Flowline" 
  // Style name used abobe is specific to a DWG file 
  // FeatureLine.StyleName // Gets or sets the Featureline's style name.
 
  featureLine.StyleName = "Flowline";
 
  // Use Autodesk.Civil.DatabaseServices.GeneralSegmentLabel.Create to add label to a feature line
 
  GeneralSegmentLabel.Create(featureLine.ObjectId, 0.5);
 
  ts.Commit();
}

 

FeatureLine
style after change –

 

 
Civil3D_FeatureLine_Style_Changed

 

and
FeatureLine with label –

 

Civil3D_FeatureLine_Label_using_API
Hope this is useful
to you.


Comments

One response to “Civil 3D FeatureLine Labeling and Style changing through .NET API”

  1. Thanks Partha. How would I go about moving the label to a different coordinate after it’s been inserted?

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading