Have you come across a situation where in you get more number of Civil 3D Surface objects using API than what is shown / visible in AutoCAD Civil 3D User Interface (UI) in Toolspace ->Prospector Tab ?
I have come across few such DWG files where-in I got more number of Surfaces using API than what is shown in Civil 3D UI Toolspace. Interestingly all those files came to me from external sources and I have no idea how those DWG files were created.
AutoCAD Civil 3D UI only iterate and shows all the Surfaces in the layouts. However in the current API implementation, we find all the surfaces in the drawing, including all the blocks and that's why we see more number of Surfaces using API.
So, how do you get the actual surfaces those are visible in Civil 3D UI Toolspace ?
Here is the relevant code snippet that demonstrates how you can get the Surfaces which are available / shown in UI Toolspace :
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
Database db = AcadApp.DocumentManager.MdiActiveDocument.Database;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
CivilDocument civilDoc = CivilApplication.ActiveDocument;
ObjectIdCollection surfaceIds = civilDoc.GetSurfaceIds();
ObjectIdCollection surfaceVisibleinUI= newObjectIdCollection();
// iterate through the list of all the surface objects
foreach (ObjectId surfaceId in surfaceIds)
{
Autodesk.Civil.DatabaseServices.Surface surface = surfaceId.GetObject(OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Surface;
BlockTableRecord record = surface.OwnerId.GetObject(OpenMode.ForRead) asBlockTableRecord;
if (record.IsLayout)
{
surfaceVisibleinUI.Add(surfaceId);
}
}
ed.WriteMessage("\nTotal Number of Surfaces available in this DWG file : " + surfaceIds.Count.ToString());
ed.WriteMessage("\n ------------------------------------------------------------- \n");
ed.WriteMessage("\nTotal Number of Surfaces Visible in UI : " + surfaceVisibleinUI.Count.ToString());
}