Creating a SectionView and setting its elevation range using .NET API

By Partha Sarkar

Civil 3D 2014 .NET API has a static method to create a new SectionView
which takes three parameters and adds a new  SectionView –   public static ObjectId Create(string sectionViewName,      ObjectId sampleLineId,    Point3d location

Once we add a new SectionView, next we
can set the maximum and minimum elevation using the following property : 

SectionView.ElevationMax -> Gets or
sets the maximum elevation of the section view.

SectionView.ElevationMin  -> Gets or sets the minimum elevation of
the section view.

 

When we add a new SectionView by
default the 'Elevation range' is set to "Automatic". If we want to
set it to "User specified" as shown in the screenshot below using the
API, then we need to set the IsElevationRangeAutomatic property to false.
Otherwise, trying to set the ElevationMin or ElevationMax will throw an exception
The minimum elevation can't be set when
elevation range is selected to automatic
.

 

SV_02

 

Here is the relevant C# .NET code
snippet on how to create a new SectionView and set the Elevation Range :

// get the Editor
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
 
//select a sampleline to add a SectionView
PromptEntityOptions selsampleline = new PromptEntityOptions("nSelect a SampleLine Object: ");
selsampleline.SetRejectMessage("nOnly Civil 3D SampleLine is allowed");
selsampleline.AddAllowedClass(typeof(SampleLine), true);
PromptEntityResult resSL = ed.GetEntity(selsampleline);
if (resSL.Status != PromptStatus.OK) return;
ObjectId sampleLineId = resSL.ObjectId;
 
 
Database db = Application.DocumentManager.MdiActiveDocument.Database;
CivilDocument civilDoc = CivilApplication.ActiveDocument;
 
using (Transaction trans = db.TransactionManager.StartTransaction())
{
 
// public static ObjectId Create(string sectionViewName, ObjectId sampleLineId, Point3d location)        
 
// lets select the location of the newly created section view
Point3d location ;
PromptPointResult ppr = ed.GetPoint("nSelect a Location for the new SectionView:");
if (ppr.Status != PromptStatus.OK)
  return;
location = ppr.Value;       
 
// add the SectionView
ObjectId sectionViewId = SectionView.Create("My_Test_SV", sampleLineId, location);
SectionView sectionView = trans.GetObject(sectionViewId, OpenMode.ForWrite) as SectionView;
SectionOverride overrideObj = sectionView.GraphOverrides[0];
overrideObj.Draw = true;
 
 
// When we add a new SectionView by default the 'Elevation range' is set to "Automatic". 
// If we want to set it to "User specified" as shown in the screesnhot below using the API, 
// then we need to set the IsElevationRangeAutomatic property to False. 
 
sectionView.IsElevationRangeAutomatic = false;
 
// Following values are specific to a Civil 3D sample DWG file        
sectionView.ElevationMin = 610.00;
sectionView.ElevationMax = 700.00;
 
trans.Commit();

I hope this is useful to you! 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading