While navigating through an array of new functionalities provided in COGO Point .NET API, I stopped at CogoPointCollection.ImportPoints() and thought, let me show a simple code snippet on how to use this API to import point data in Civil 3D.
CogoPointCollection class in Civil 3D 2013 .NET API, has overloaded method ImportPoints() which we can use to import COGO Points in a DWG file. In this example, we will explore how to use CogoPointCollection.ImportPoints (String, PointFileFormat) that takes a string pointFileFullName and PointFileFormat fileFormat.
While trying to execute my C# code sample to import points from a point file using CogoPointCollection.ImportPoints() I stumbled upon an issue. I was trying to import Point data in an empty DWG file from a Civil 3D tutorial text data file and I found CogoPointCollection.ImportPoints() call throws an exception -"No Points were transferred from the source". After a discussion with a colleague from Civil 3D engineering team we found there is an issue in .NET version of ImportPoints(). Since we have spotted this issue now, we will work on fixing it ASAP; in the meantime, simple workaround is just adding a single COGO point in the drawing which you can delete later. If there is any existing COGO point object in the Civil 3D drawing file then you will find ImportPoints() function call brings in all the point from the desired data source without any issue.
BTW – You will also see the “Duplicate Point Number” dialog box while trying to import the points to resolve the duplicate point number conflicts. I find Isaac already mentioned about this in his blog post on COGO Points Renumbering.
// This point file is included as a sample for Civil 3D tutorials:
string pointFilePath = @"C:\Program Files\Autodesk\AutoCAD Civil 3D 2013\Help\Civil Tutorials\";
string pointFileName = pointFilePath + "Existing Ground Points - PENZD.txt";
//The 2nd parameter is the file format for the point file
// of type Autodesk.Civil.DatabaseServices.PointFileFormat.
string pointFileFormatName = "PENZD (space delimited)";
PointFileFormat pointFileFormat = PointFileFormatCollection.GetPointFileFormats(db)[pointFileFormatName];
CogoPointCollection.ImportPoints(pointFileName, pointFileFormat);