In AutoCAD Civil 3D 2013 .NET API, there is a new function included which extracts the surface watershed information from the terrain surface. TinSurface.ExtractWatershed() takes SurfaceExtractionSettingsType as input parameter and it returns ObjectIdCollection for entities that can be Polyline3d or Hatch. Here is a C#.NET code snippet which demonstrates usage of TinSurface.ExtractWatershed() :
//select a surface
PromptEntityOptions selSurface = new PromptEntityOptions("nSelect a Tin Surface: ");
selSurface.SetRejectMessage("nOnly Tin Surface is allowed");
selSurface.AddAllowedClass(typeof(TinSurface), true);
PromptEntityResult resSurface = ed.GetEntity(selSurface);
if (resSurface.Status != PromptStatus.OK) return;
ObjectId surfaceId = resSurface.ObjectId;
Database db = Application.DocumentManager.MdiActiveDocument.Database;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
TinSurface surface = trans.GetObject(surfaceId, OpenMode.ForRead) as TinSurface;
// Extract ExtractWatershed() from the TinSurface
// The extracted entities can be Polyline3d or Hatch.
ObjectIdCollection wsentityIds;
wsentityIds = surface.ExtractWatershed(Autodesk.Civil.SurfaceExtractionSettingsType.Plan);
for (int i = 0; i < wsentityIds.Count; i++)
{
ObjectId entityId = wsentityIds[i];
Polyline3d watershedLine = entityId.GetObject(OpenMode.ForRead) as Polyline3d;
if (watershedLine != null)
{
// Access watershedLine Properties
}
Hatch watersheHatch = entityId.GetObject(OpenMode.ForRead) as Hatch;
if (watersheHatch != null)
{
// Access watersheHatch Properties
}
}
trans.Commit();
}

Leave a Reply