I am trying to write a routine that exports point to a CSV file. I would like the Point Elevation, but I only see the Z location property. Here is the code. Often our points are at a elevation of zero, but the elevation property is at the design grade, so the Location would not be correct. What am I missing?
<CommandMethod("ExportPoints")> _ Public Sub ExportPointsToCSV() Dim myDoc As Document = AcadNETApp.DocumentManager.MdiActiveDocument Dim myCivilDoc As Autodesk.Civil.ApplicationServices.CivilDocument myCivilDoc = CivilApplicationManager.ActiveCivilDocument Dim mySW As New IO.StreamWriter("C:\test.csv") Using myTrans As Transaction = myDoc.TransactionManager.StartTransaction For Each myPointID As ObjectId In myCivilDoc.GetAllPointIds Dim myPoint As PointEntity = myPointID.GetObject(OpenMode.ForRead) mySW.WriteLine(myPoint.PointNumber & "," & _ myPoint.Location.Y.ToString & "," & _ myPoint.Location.X.ToString & "," & _ myPoint.Location.Z.ToString & "," & _ Left(myPoint.FullDescription, 15)) Next End Using mySW.Flush() mySW.Close() mySW.Dispose() End Sub
The Z is the point's elevation. Where it is displayed in the drawing is controlled by the style, so the Location.Z should never change due to how it's displayed.
Thanks for taking a look at this Jeff.
When I select a point in the drawing and view the properties, it shown me a northing, easting and elevation. When I run this routine, the elevation of every point is 0, regardless of the elevation shown in the properties dialog. How do I retrieve the point elevation displayed in the drawing?
Oops, sorry about that! I really should learn to not post when I'm in a hurry.
The PointEntity is a newer (2011) addition to the .NET API and it appears it is not completely done. I've always used the COM API to get the elevation which IS a property of the AeccPoint object.
Thanks again Jeff. That was the guidance I needed.and I was able to get the code below to work.
<CommandMethod("ExportPoints")> _ Public Sub ExportPointsToCSV() 'This routine still relies on the COM Interface in order to get the Point elevation, not the location Dim myDoc As Document = AcadNETApp.DocumentManager.MdiActiveDocument Dim myCivilDoc As AeccDocument myCivilDoc = CivilApplicationManager.COMActiveCivilDocument Dim myProjectInformation(2) As String myProjectInformation = myAcadApp.getProjectInformation(myDoc) Dim sPath As String = myProjectInformation(2) & "\08 Site Construction\Point Files\" & myProjectInformation(1) & "." & Now().ToString("yyyy-MM-dd") & ".csv" MsgBox(sPath) Dim mySW As New IO.StreamWriter(sPath) Dim myPoints As AeccPoints = myCivilDoc.Points Using myTrans As Transaction = myDoc.TransactionManager.StartTransaction For Each myPoint As AeccPoint In myCivilDoc.Points mySW.WriteLine(myPoint.Number & "," & _ myPoint.Northing & "," & _ myPoint.Easting & "," & _ myPoint.Elevation & "," & _ Left(myPoint.FullDescription, 15)) Next End Using mySW.Flush() mySW.Close() mySW.Dispose() End Sub
I did notice that the resulting file was not in point number order. Is there a way to easily retrieve the myCivilDoc.Points collection already sorted without assigning it to an array?
Thanks again. I'd been struggling with that for far longer than I hoped, and I finally worked through the COM .NET confusion I have had in migrating from VBA.
Access a broad range of knowledge to help get the most out of your products and services.