Object data, and multiple fields.

Discussion in 'AutoCAD' started by kb, Sep 17, 2003.

  1. kb

    kb Guest

    Hi,

    Currently I have a project that querys a drawing, and gets the object data for each object in the drawing. It cycles through all the objects collecting the object data which is eventually popluated to a database.



    However, it only retrieves one record for each object. I need to collect another record for the same object that is within the same object data table, but in another field. The first field is an integer, the second field is a string.


    IF you would like to see the project I send the code.

    thanks
     
    kb, Sep 17, 2003
    #1
  2. kb

    LochDhu Guest

    Need to use ODFieldDef's to get the field collection. Look at this sample - watch for word wrap:



    Sub getOD()

    Dim acadApp As Object Dim amap As AcadMap

    Set acadApp = ThisDrawing.Application Set amap = acadApp.GetInterfaceObject("AutoCADMap.Application")     Dim odTables As odTables     Dim odTable As odTable     Dim RecordIterator As odRecords     Dim odRecord As odRecord     Dim odValue As ODFieldValue     Dim msg As String     Dim acadObj As AcadObject

    For Each acadObj In ThisDrawing.ModelSpace         msg = ""                 '' get the selected object data table and iterator         Set odTables = amap.Projects(ThisDrawing).odTables         Set odTable = odTables.Item("Trees")         'Set odTable = amap.Projects(ThisDrawing).odTables.Item("Beer")             Set RecordIterator = odTable.GetODRecords         ' initilize iterator on entity              If RecordIterator.Init(acadObj, False, False) = True Then

    '' oops, that entity has no od attached to specified table                 If RecordIterator.IsDone Then                     msg = msg & "Entity has no data from Object Data Table: " & odTable.Name                 End If

    '' loop through all attached records from specified table                 Do Until RecordIterator.IsDone

    '' get record data                     Set odRecord = RecordIterator.Record

    '' initialize field counter                     count = 0

    '' loop through each od field                         For Each odValue In odRecord

    '' get field name from defs                             msg = msg & odTable.ODFieldDefs.Item(count).Name

    '' and show field value                             Select Case odValue.Type                             Case 0, 1, 2, 3                                 msg = msg & " = " & CStr(odValue.Value) & Chr(10)                             Case 4                                 msg = msg & " = " & CStr(odValue.Value.X) & "," & CStr(odValue.Value.Y) & "," & CStr(odValue.Value.X) & Chr(10)                             End Select                               count = count + 1                         Next

    '' there may be more records attached                 RecordIterator.Next             Loop



    '' error getting iterator

    Else

    '' report the bad news             msg = "Error iterating Object Data Table: " & odTable.Name         End If

    '' update text box         MsgBox msg     Next

    Set amap = Nothing     Set acadApp = Nothing End Sub
     
    LochDhu, Sep 17, 2003
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.