AutoCAD Civil3D: Unable to add point groups after opening windows Form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey all! I am writing a program that opens a form when the program is run. I have no problems opening the form or hopping between methods. The problem arises when I get the active civil document (or utilize it) after the form is closed. I know the import Point section is correct because it works fine in a Class Library by itself. So somewhere the form is causing problems. I have tried a multitude of solutions including CommandFlags, activating the window, and focusing the window. (Commented Lines in snippet) Any help would be appreciated! I am probably just being blind. Thanks!
Class 1
Public Class Class1
Public Shared acadDoc As Document
Public Shared civilDoc As CivilDocument
<CommandMethod("MHLBF", CommandFlags.Session)>
Public Sub RunMHLB()
acadDoc = Application.DocumentManager.MdiActiveDocument
civilDoc = CivilApplication.ActiveDocument
//acadDoc.LockDocument()
Dim f As New Form1
f.Show()
End Sub
Public Sub Insertpoint()
//Dim app As AcadApplication = Application.AcadApplication
//app.ActiveDocument.Activate()
//acadDoc.Window.Focus()
Using acCurDb As Database = acadDoc.Database
Using trans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim pointFileName As String = "C:\Users\jdalton\Desktop\091021_PCV3_ASB_SH.csv"
Dim pointFileFormatName As String = "PNEZD (comma delimited)"
Dim pointFileFormat As PointFileFormat = PointFileFormatCollection.GetPointFileFormats(acCurDb)(pointFileFormatName)
Dim pointGroupId As ObjectId = civilDoc.PointGroups.Add("AddedPoints")
Dim result As UInteger = CogoPointCollection.ImportPoints(pointFileName, pointFileFormat, pointGroupId)
trans.Commit()
End Using
End Using
End Sub
End Class
Form Class
Public Class Form1
Public Sub InsButton_Click(sender As Object, e As EventArgs) Handles InsButton.Click
Close()
Dispose()
Dim callMethod As Class1 = New Class1
callMethod.Insertpoint()
End Sub
End Class
Edit: Upon further inspection, ObjectLeftOnDisk = 'pointGroupIf.ObjectLeftOnDisk' threw an exception of type 'System.AccessViolationException' I also get this error. So maybe my context is screwed up or I am doing something horribly wrong
Edit 2: Continuing my investigation, if I click the app just before it grabs the active document and starts the transaction, it works. Still trying to make the app become the active window. Any help would be appreciated!
Attached is the Error in Visual Studio and the Error in CAD