Editing ODTables with VBA

Editing ODTables with VBA

Anonymous
Not applicable
532 Views
2 Replies
Message 1 of 3

Editing ODTables with VBA

Anonymous
Not applicable
I have a drawing on wich the objects have several ODTables atached to.
I am trying to, for each object, scan the contents of one ODTable, and then
change the records on another ODTable.

The chosen way is to create 2 diferent ODRecords for the same object at the
time. The first one is for scaning the data in the first table (openmode
false), and the other for updating the second table (openmode true).


I made this code:

............................................................................
...
Dim amap As AcadMap
Set amap =
ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application.2")

'ODRecords from ODTable1
Dim odRecordsCxT As odRecords
Set odRecordsCxT =
amap.Projects(ThisDrawing).ODTables.Item(ODtable1_name).GetODRecords

'ODRecords from ODTable2
Dim odRecordsCx As odRecords
Set odRecordsCx =
amap.Projects(ThisDrawing).ODTables.Item(ODTable2_name).GetODRecords

Dim obj As AcadObject
For Each obj In ThisDrawing.ModelSpace
a = odRecordsCxT.Init(obj, False, False) 'table1
If Not odRecordsCxT.IsDone Then
ID = odRecordsCxT.Record.Item(0).Value
End If

b = odRecordsCx.Init(obj, True, False) 'table2
If Not odRecordsCx.IsDone Then
'Code for updating table 2
End If
Next
............................................................................
.............................................


But it is not working, as the second Init procedure (for table 2) returns
false.

If i opened the second ODRecords with OpenMode false, then i get a true
result for the init, but then i am not able to update the records.

If i switch the init´s order, then i get a 'true' result for table2, but
'false' for table1, even if on a OpenMode false.

If i try OpenMode false for both the ODRecords, then i can get acess to the
records, but i can´t update any of them.

So, it seems that for one single object, ther can be more than one opened
ODTable but only for readonly purposes. For updating, there can be only one
odtable opend.

Hpw can i solve my problem?
0 Likes
533 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
I ran into this a while back as well. Two alternatives that come to mind. First, make sure to destroy the object for Table A before going to Table B - this requires that you re-initial it for every loop.


For Each obj In ThisDrawing.ModelSpace
Set odRecordsCxT = amap.Projects(ThisDrawing).ODTables.Item("Table1").GetODRecords
a = odRecordsCxT.Init(obj, False, False) 'table1
If Not odRecordsCxT.IsDone Then
ID = odRecordsCxT.Record.Item(0).Value
End If
Set odRecordsCxT = Nothing
Set odRecordsCx = amap.Projects(ThisDrawing).ODTables.Item("Table2").GetODRecords

b = odRecordsCx.Init(obj, True, False) 'table2
If Not odRecordsCx.IsDone Then
'Code for updating table 2
End If
Set odRecordsCx = Nothing
Next


Or, loop through Table A and create collection or an array to hold each obj and it's ID - then close it and loop through the array and open Table B for edit. I don't care for this method but it should work.

Hope That Helps,

Scott
0 Likes
Message 3 of 3

Anonymous
Not applicable
Yes, it helped. Thanks a lot.

PM
0 Likes