Hope it is okay to resurrect this. I usually try for late binding to support as many versions of possible with a single DLL where COM is required. But I cannot get fig.GetObjectId(oAeccSurveyDB) to work in this case where the fig.IsInDrawing(oAeccSurveyDB) call works fine. The exception is Type mismatch. (Exception from HRESULT: 0x8002802A (TYPE_E_WRONGTYPEKIND))
Code below shows TEST1 which works and TEST2 which does not. The only difference is the the variable definition "As Object".
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.Civil.DatabaseServices
Imports Autodesk.AECC.Interop.Survey
Imports System
Public Class Main
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Public Sub Initialize() Implements IExtensionApplication.Initialize
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor()
ed.WriteMessage("Initializing - " & My.Application.Info.AssemblyName)
End Sub
Public Sub Terminate() Implements IExtensionApplication.Terminate
End Sub
<CommandMethod("TEST1")> Public Sub Test1()
Dim oAcadApp As Autodesk.AutoCAD.Interop.AcadApplication = Nothing
Dim oAeccSurveyApp As Autodesk.AECC.Interop.UiSurvey.AeccSurveyApplication = Nothing
Dim oAeccSurveyDoc As Autodesk.AECC.Interop.UiSurvey.AeccSurveyDocument = Nothing
Dim oAeccSurveyDB As Autodesk.AECC.Interop.Survey.AeccSurveyDatabase = Nothing
oAcadApp = GetObject(, "AutoCAD.Application")
oAeccSurveyApp = oAcadApp.GetInterfaceObject("AeccXUiSurvey.AeccSurveyApplication.10.4")
oAeccSurveyDoc = oAeccSurveyApp.ActiveDocument 'AeccSurveyCOMDoc
oAeccSurveyDB = oAeccSurveyApp.ActiveDocument.Database
Using trans As Autodesk.AutoCAD.DatabaseServices.Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()
Dim oCurrentProject As AeccSurveyProject = oAeccSurveyDB.CurrentProject
For Each fig As AeccSurveyFigure In oCurrentProject.Figures
If fig.IsInDrawing(oAeccSurveyDB) Then
Dim comID As Long = fig.GetObjectId(oAeccSurveyDB)
Dim netID As Object = oAeccSurveyDB.ObjectIdToObject(comID)
Dim figID As Integer = fig.ID
End If
Next
End Using
End Sub
<CommandMethod("TEST2")> Public Sub Test2()
Dim oAcadApp As Object = Nothing
Dim oAeccSurveyApp As Object = Nothing
Dim oAeccSurveyDoc As Object = Nothing
Dim oAeccSurveyDB As Object = Nothing
oAcadApp = GetObject(, "AutoCAD.Application")
oAeccSurveyApp = oAcadApp.GetInterfaceObject("AeccXUiSurvey.AeccSurveyApplication.10.4")
oAeccSurveyDoc = oAeccSurveyApp.ActiveDocument 'AeccSurveyCOMDoc
oAeccSurveyDB = oAeccSurveyApp.ActiveDocument.Database
Using trans As Autodesk.AutoCAD.DatabaseServices.Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()
Dim oCurrentProject As Object = oAeccSurveyDB.CurrentProject
For Each fig As Object In oCurrentProject.Figures
If fig.IsInDrawing(oAeccSurveyDB) Then
Dim comID As Long = fig.GetObjectId(oAeccSurveyDB)
Dim netID As Object = oAeccSurveyDB.ObjectIdToObject(comID)
Dim figID As Integer = fig.ID
End If
Next
End Using
End Sub
End Class
System.Runtime.InteropServices.COMException (0x8002802A): Type mismatch. (Exception from HRESULT: 0x8002802A (TYPE_E_WRONGTYPEKIND))
at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)
at Main.Test2() in F:\Visual Studio\Projects\Main.vb:line 73
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()