Trying to export points to a csv with the object data that is attached to the point. I can use this and it works great for smaller projects, but crashes every time when I try to export a larg amount of points. The most it has successfully exported was 9000 points but on average it usually will get to 3000 points before i get a fatal error and everything crashes.
Dim CSV_FileName As String = Nothing
' navigate to the point text csv file using a file dialog
Dim dlg As New System.Windows.Forms.SaveFileDialog()
dlg.InitialDirectory = "C:\"
dlg.Filter = "csv excel files (*.csv)|*.csv|All files (*.*)|*.*"
If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
CSV_FileName = dlg.FileName().ToString
End If
Dim oPoints As Autodesk.AECC.Interop.Land.AeccPoints
Dim sFilename As String
'Dim iCount As Integer
oPoints = oAeccDB.Points
sFilename = CSV_FileName
Dim inWriter As New StreamWriter(sFilename)
Dim pid, desc As String
Dim x, y, z As Double
Dim oPoint As Autodesk.AECC.Interop.Land.AeccPoint
Dim cnt As Long = oPoints.Count
Dim expline(cnt) As String
Dim n As Long
For n = 0 To cnt - 1
oPoint = oPoints.Item(n)
pid = oPoint.Number
x = oPoint.Easting
y = oPoint.Northing
z = oPoint.Elevation
desc = oPoint.RawDescription
Dim id As ObjectId = PointEntity.FromAcadObject(oPoint)
Dim tables As Tables
tables = HostMapApplicationServices.Application.ActiveProject.ODTables
Dim records As Records = tables.GetObjectRecords(Convert.ToUInt32(0), id, Constants.OpenMode.OpenForRead, False)
' Iterate through all records
Dim record As Record = records.Item(0)
'For Each record In records
Dim msg(12) As String
' Get the table
Dim table As ObjectData.Table = tables(record.TableName)
Dim str As String = Nothing
' Get record info
Dim i As Integer
Dim upbound As Integer = Record.Count - 1
For i = 2 To upbound - 1
Dim val As MapValue = Record(i)
Str = val.StrValue
msg(i - 1) = str
Next i
inWriter.WriteLine(pid & "," & y & "," & x & "," & z & "," & desc & "," & msg(1) & "," & msg(2) & "," & msg(3) & "," & msg(4) & "," & msg(5) & "," & msg(6) & "," & msg(7) & "," & msg(8) & "," & msg(9) & "," & msg(10) & "," & msg(11))
' Next
Next n
inWriter.Flush()
inWriter.Dispose()
End Sub
Solved! Go to Solution.
Solved by Hallex. Go to Solution.
Solved by Hallex. Go to Solution.
If autocad wants to send a crash report, you can use the "View files" option and view the ".dmp" file. Scroll down to the section called "appdata". You might see some more info on where/why the crash occurs.
If the problem occurs writing data to your csv file, you could try stringbuilder 1st. Dump all of your point data into a stringbuilder, and then stream that to file. You could also create large chunks with stringbuilder and write the chunks to file.
This is just a guess - I think it is obvious your code is OK.
do not know how to read the .dmp files. I tried using the stringbuilder and it did speed up the export but it still crashes with large amount of numbers. I did a little more debugging and found that most of the time it crashed when it gets to the line:
oPoints = oAeccDB.Points
I tried removing that line and replacing my first for statement with
For Each oPoint In oAeccDB.Points
then it crashed at that line. Anymore suggestions?
Try create StringBulder and populate it with text lines
then write in in the csv file:
sw.Write (sb.ToString());
Iow, do it separatelly
~'J'~
You can view the dmp file with the button at the bottom - I think it says "View file contents". Select the dmp file, then click on the view button. It's been awhile since I have seen a crash report, but everything you need is on that dialog.
I am a map 3d user and have no experience with other verticals like Land Desktop. Sorry!
Thanks for your help finally got it to work with the stringbuilder. Here is my final code that worked.
<CommandMethod("exporter")> _
Public Sub ShowObjectDataInfo()
Try
If oAcadApp Is Nothing Then
oAcadApp = GetObject(, "AutoCAD.Application")
End If
Catch ex As System.Exception
ed.WriteMessage(ex.Message)
End Try
oAeccApp = oAcadApp.GetInterfaceObject("AeccXUiLand.AeccApplication.9.0")
oAeccDoc = oAeccApp.ActiveDocument
oAeccDB = oAeccApp.ActiveDocument.Database
Dim CSV_FileName As String = Nothing
' navigate to the point text csv file using a file dialog
Dim dlg As New System.Windows.Forms.SaveFileDialog()
dlg.InitialDirectory = "C:\"
dlg.Filter = "csv excel files (*.csv)|*.csv|All files (*.*)|*.*"
If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
CSV_FileName = dlg.FileName().ToString
End If
Dim oPoints As Autodesk.AECC.Interop.Land.AeccPoints
Dim sFilename As String
'Dim iCount As Integer
oPoints = oAeccDB.Points
sFilename = CSV_FileName
Dim builder As New StringBuilder
Dim inWriter As New StreamWriter(sFilename)
Dim desc As String
Dim pid As Integer
Dim x, y, z As Double
Dim oPoint As Autodesk.AECC.Interop.Land.AeccPoint = Nothing
For Each oPoint In oAeccDB.Points
pid = oPoint.Number
x = oPoint.Easting
y = oPoint.Northing
z = oPoint.Elevation
desc = oPoint.RawDescription
Dim id As ObjectId = PointEntity.FromAcadObject(oPoint)
Dim tables As Tables
tables = HostMapApplicationServices.Application.ActiveProject.ODTables
Dim records As Records = tables.GetObjectRecords(Convert.ToUInt32(0), id, Constants.OpenMode.OpenForRead, False)
' Iterate through all records
Dim record As Record = records.Item(0)
'For Each record In records
Dim msg(12) As String
' Get the table
Dim table As ObjectData.Table = tables(record.TableName)
Dim str As String = Nothing
' Get record info
Dim i As Integer
Dim upbound As Integer = record.Count - 1
For i = 2 To upbound - 1
Dim val As MapValue = record(i)
str = val.StrValue
msg(i - 1) = str
Next i
builder.Append(pid & "," & y & "," & x & "," & z & "," & desc & "," & msg(1) & "," & msg(2) & "," & msg(3) & "," & msg(4) & "," & msg(5) & "," & msg(6) & "," & msg(7) & "," & msg(8) & "," & msg(9) & "," & msg(10) & "," & msg(11)).AppendLine()
Next
Dim s As String = builder.ToString
inWriter.WriteLine(s)
inWriter.Flush()
inWriter.Dispose()
builder.Clear()
GC.Collect()
End Sub
Just noticed another bug. The drawing closes out ok but when I try to close out of Civil3d after running my command it crashes. Is there something that I am not closing or disposing of properly?
I recommend you to use in your code the following syntax
- Use Try ... Catch .. finally code block, it allow you to find
the problem points of code easily
- use Using.. End Using for all non-resident objects, e.g.:
using sw as SreamWriter= ....
sw.Write(...)
end using '' no need to close or dispose
same way for StringBuilder, i that case you don't have to Dispose
both of them as well
~'J'~
I just imagine how it would be, coz I haven't have Civil3d on my end
See code
<CommandMethod("exporter")> _ Public Sub ShowObjectDataInfo() Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor Dim oAcadApp As AcadApplication = Application.AcadApplication Try If oAcadApp Is Nothing Then oAcadApp = GetObject(, "AutoCAD.Application") End If Catch ex As System.Exception ed.WriteMessage(ex.Message) End Try oAeccApp = oAcadApp.GetInterfaceObject("AeccXUiLand.AeccApplication.9.0") oAeccDoc = oAeccApp.ActiveDocument oAeccDB = oAeccApp.ActiveDocument.Database Dim CSV_FileName As String = Nothing Try ' navigate to the point text csv file using a file dialog Dim dlg As New System.Windows.Forms.SaveFileDialog() dlg.InitialDirectory = "C:\" dlg.RestoreDirectory = True dlg.Filter = "csv excel files (*.csv)|*.csv|All files (*.*)|*.*" If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then CSV_FileName = dlg.FileName().ToString End If Dim oPoints As Autodesk.AECC.Interop.Land.AeccPoints Dim sFilename As String Dim iCount As Integer oPoints = oAeccDB.Points sFilename = CSV_FileName Dim builder As New StringBuilder Dim desc As String Dim pid As Integer Dim x, y, z As Double For Each oPoint In oAeccDB.Points pid = oPoint.Number x = oPoint.Easting y = oPoint.Northing z = oPoint.Elevation desc = oPoint.RawDescription Dim id As ObjectId = PointEntity.FromAcadObject(oPoint) Dim tables As Tables tables = HostMapApplicationServices.Application.ActiveProject.ODTables Dim records As Records = tables.GetObjectRecords(Convert.ToUInt32(0), id, Constants.OpenMode.OpenForRead, False) ' Iterate through all records Dim record As Record = records.Item(0) For Each record In records Dim msg(12) As String ' Get the table Dim table As ObjectData.Table = tables(record.TableName) Dim str As String = Nothing ' Get record info Dim i As Integer Dim upbound As Integer = record.Count - 1 For i = 2 To upbound - 1 Dim val As MapValue = record(i) str = val.StrValue msg(i - 1) = str() Next i Dim rec As String = String.Format("{0}" + vbTab + "{1}" + vbTab + "{2}" + vbTab + "{3}" + vbTab + _ "{4}" + vbTab + "{5}" + vbTab + "{6}" + vbTab + "{7}" + vbTab + _ "{8}" + vbTab + "{9}" + vbTab + "{10}" + vbTab + "{11}" + vbTab + _ "{12}" + vbTab + "{13}" + vbTab + "{14}" + vbTab + "{15}", pid, y, x, z, desc, msg(1), msg(2), msg(3), msg(4), msg(5), msg(6), msg(7), msg(8), msg(9), msg(10), msg(11)) builder.AppendLine(rec) Next Using inWriter As New StreamWriter(sFilename) inWriter.WriteLine(builder.ToString) inWriter.Flush() End Using GC.Collect() Catch ex As System.Exception MsgBox(ex.Message + vbLf + ex.StackTrace) Finally End Try End Sub
~'J'~