Private Sub Button_COMP_Click(sender As Object, e As EventArgs) Handles Button_COMP.Click
Dim m_doc As CivilDocument = Nothing
Dim m_trans As Transaction = Nothing
Dim m_Database As Database = Nothing
Dim m_Editor As Editor = Nothing
Dim docCol As Autodesk.AutoCAD.ApplicationServices.DocumentCollection = Application.DocumentManager
m_Database = docCol.MdiActiveDocument.Database
m_Editor = docCol.MdiActiveDocument.Editor
m_doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument()
Dim CogoPoints As CogoPointCollection = m_doc.CogoPoints
'Confirmed as valid link to CogoPointCollection
Dim oAlignments As ObjectIdCollection
oAlignments = m_doc.GetAlignmentIds
Dim b As Boolean
b = False
Dim s As String
Dim oAlignment As Alignment = Nothing 'Alignment used for comps.
Dim oProfile As Profile = Nothing 'Profile for 3D comps (see b2D_Comps)
Dim b2D_Comps As Boolean = False
Dim dSta As Double
Dim sRawSta As String
Dim Northing As Double
Dim Easting As Double
Dim Elevation As Double
Dim dOffset As Double 'Offset for point calculations i.e. Alignment + Hub Offset
If TextBox_ALIGNOFF.Text = "" Then
TextBox_ALIGNOFF.Text = "0.00"
End If
If TextBox_HUBOFF.Text = "" Then
TextBox_HUBOFF.Text = "0.00"
End If
dOffset = Double.Parse(TextBox_ALIGNOFF.Text) + Double.Parse(TextBox_HUBOFF.Text)
Dim dElevMod As Double
If TextBox_ELEV_MOD.Text = "" Then
TextBox_ELEV_MOD.Text = "0.00"
End If
dElevMod = Double.Parse(TextBox_ELEV_MOD.Text)
m_trans = m_Database.TransactionManager.StartTransaction()
'Set oAlignment
For Each ObjId As ObjectId In oAlignments
oAlignment = m_trans.GetObject(ObjId, OpenMode.ForRead)
If oAlignment.Name = ComboBox_ALIGN.Text Then
b = True
Exit For
End If
Next
If b = False Then
MsgBox("Alignment not defined.", MsgBoxStyle.Exclamation)
Exit Sub
End If
'Set oProfile or b2D_Comps
If ComboBox_Profiles.Text = "" Then
s = "Profile NOT Set." + vbCrLf + "Points are 2D?"
Dim Answer As MsgBoxResult = MsgBox(s, MsgBoxStyle.YesNo)
If Answer = MsgBoxResult.Yes Then
b2D_Comps = True
Else
Exit Sub
End If
Else
b = False
Dim oProfiles As ObjectIdCollection
oProfiles = oAlignment.GetProfileIds
For Each ObjIdPro As ObjectId In oProfiles
oProfile = m_trans.GetObject(ObjIdPro, OpenMode.ForRead)
If oProfile.Name = ComboBox_Profiles.Text Then
b = True
Exit For
End If
Next
End If
'Left side comps
If RadioButton_L.Checked = True Or RadioButton_B.Checked = True Then
Dim dOffsetL As Double
dOffsetL = dOffset * (-1)
For Each row In DataGridView_STAOFF.Rows
dSta = Double.Parse(row.Cells(0).Value)
sRawSta = row.Cells(1).Value
If RadioButton_B.Checked = True Then
sRawSta = sRawSta.Replace("L_R", "L")
End If
oAlignment.PointLocation(dSta, dOffsetL, Easting, Northing)
If b2D_Comps = True Then
Elevation = 0
Else
Elevation = oProfile.ElevationAt(dSta) + dElevMod
End If
Dim CompPt As New Point3d(Easting, Northing, Elevation)
'MsgBox(CompPt.X)
'MsgBox(CompPt.Y)
'MsgBox(CompPt.Z)
Dim i As Integer = CogoPoints.Count
MsgBox(i) '************************************************CRASHES AFTER THIS*************************
Try
CogoPoints.Add(CompPt)
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.Message)
End Try
MsgBox("Test")
'Dim cogoPoint As CogoPoint = TryCast(pointId.GetObject(OpenMode.ForWrite), CogoPoint)
'cogoPoint.RawDescription = sRawSta
Next
End If 'Left side comps