Surface.GetBoundedVolumes() is a new inclusion in 2013 release of AutoCAD Civil 3D .NET API, which calculates the volume of a closed area. GetBoundedVolumes(Point3dCollection polygon) takes a Point3dCollection containing points that define the vertices of a closed area and an optional elevation datum (If you do not provide an elevation datum, the method uses 0.0). One point to be noted here, the first and last point in the vertices collection must be the same, i.e. the polygon must be closed. GetBoundedVolumes() method returns a SurfaceVolumeInfo object that includes values for net volume, cut volume, and fill volume.
Here is a C# code snippet which demonstrates usage of this API function in AutoCAD Civil 3D 2013 :
// Get the AutoCAD Editor
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
//select a polygon
PromptEntityOptions selPline = new PromptEntityOptions("nSelect a Closed Polyline: ");
selPline.SetRejectMessage("nOnly polyline is allowed");
selPline.AddAllowedClass(typeof(Polyline), true);
PromptEntityResult resPline = ed.GetEntity(selPline);
if (resPline.Status != PromptStatus.OK) return;
ObjectId plineId = resPline.ObjectId;
Database db = Application.DocumentManager.MdiActiveDocument.Database;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
CivilDocument civilDoc = CivilApplication.ActiveDocument;
TinVolumeSurface tinVolSurf = null;
ObjectIdCollection SurfaceIds = civilDoc.GetSurfaceIds();
foreach (ObjectId surfaceId in SurfaceIds)
{
Autodesk.Civil.DatabaseServices.Surface oSurface = surfaceId.GetObject(OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Surface;
if (oSurface.GetType().ToString()== "Autodesk.Civil.DatabaseServices.TinVolumeSurface")
{
tinVolSurf = (TinVolumeSurface)oSurface;
break; // In this example we are dealing with the 1st TinVolume Surface
}
}
Polyline pline = trans.GetObject(plineId, OpenMode.ForRead) as Polyline;
Point3dCollection pointcoll = new Point3dCollection();
for (int i = 0; i < pline.NumberOfVertices; i++)
{
pointcoll.Add(pline.GetPoint3dAt(i));
}
// the start point and the end point must be the same.
pointcoll.Add(pline.StartPoint);
SurfaceVolumeInfo svinfo = tinVolSurf.GetBoundedVolumes(pointcoll);
ed.WriteMessage("n*********Bounded Volume Result from API Function call **************");
ed.WriteMessage(String.Format("nCut volume: {0}n Fill volume: {1}n Net volume: {2}n", svinfo.Cut, svinfo.Fill, svinfo.Net));
trans.Commit();
}
And here is a screenshot of Bounded Volume calculation performed using API as well as using the Civil 3D Volumes utility tools:


Leave a Reply