ODTables.Item(tableName) does not work on Windows7/Vista?

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 = Nothing    For 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 AcadMapDim tbl As ODTableDim tbls As ODTablesSet amap = ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")Debug.Print amap.Projects.Count '' workaroundSet tbls = amap.Projects(ThisDrawing).ODTablesIf (tbls.Count) > 0 ThenFor Each tbl In tblsIf tbl.Name = "Building" Then ‘ set OD Table name here as per your dataDebug.Print tbl.NameEnd IfNextEnd IfEnd Sub<code_end>

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading