Adding Bands data to Civil 3D Profile View using .NET API

By Partha Sarkar

In this example we see how to add Profile View data bands to a Profile View in AutoCAD Civil 3D using .NET API.

Here we add the band for the top band. In AutoCAD Civil 3D "Profile View Properties" dialog box, you will notice 'Location' drop down box under the 'List of Bands' and it has two options -  'Top of Profile View' or 'Bottom of Profile View'. In this example I am going to add a new band in the 'Top of Profile View'.

 

Top of Profile View before adding the data band :

  Civil_3D_ProfileView_TopBand_Empty

 

And After adding the data band :

Civil_3D_ProfileView_TopBand_API
 

And here is the C# .NET code snippet : 

Database db = AcadApp.DocumentManager.MdiActiveDocument.Database;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
  CivilDocument civilDoc = CivilApplication.ActiveDocument;
 
  //open the profile view
  ProfileView pv = trans.GetObject(pvId, OpenMode.ForWrite) asProfileView;
 
  //get the style of the first Bottom Bands          
  ObjectId bandStyleId = pv.Bands.GetBottomBandItems()[0].BandStyleId;
 
  //now access the collection of top band
  ProfileViewBandItemCollection topBandItems = pv.Bands.GetTopBandItems();          
 
  //add a new one (using the above style)
  topBandItems.Add(bandStyleId);
 
  //now Set the Top Bands
  pv.Bands.SetTopBandItems(topBandItems);          
 
  trans.Commit();
 
}

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading