By Daniel Du
Issue
I am migrating my Map 3D VBA application to .NET, but when I call ODTables.Item(strTableName), it always crashes AutoCAD on Windows 7/Vista, and it works well on WinXP.
Solution
You can use following workaround on Windows 7/Vista to solve this problem:
VB.NET:
<code_begin>
Dim ODTbl As AutocadMAP.ODTable
ODTbl = NothingFor index = 0 To ODTbls.Count - 1
Debug.WriteLine( ODTbls.Item(index).Name.ToString())
If (ODTbls.Item(index).Name.ToString() = TargetTable) Then
ODTbl = ODTbls.Item(index)
Exit For
End If
Next
<code_end>
VBA code:
<code_begin>
Public Sub GetMapApp()
Dim amap As AcadMap
Dim tbl As ODTable
Dim tbls As ODTables
Set amap = ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")
Debug.Print amap.Projects.Count
'' workaround
Set tbls = amap.Projects(ThisDrawing).ODTables
If (tbls.Count) > 0 Then
For Each tbl In tbls
If tbl.Name = "Building" Then ‘ set OD Table name here as per your data
Debug.Print tbl.Name
End If
Next
End If
End Sub<code_end>