Getting Object Data

AutoCAD Map 3D .NET API

 
Getting Object Data
 
 
 

To get all object data records from a single table for a drawing object:

  • Get the ObjectData.Tables object for the drawing.
  • Get the individual table.
  • Get the ObjectData.Records collection for the object, using one of the GetObjectTableRecords() methods.
  • Iterate through the records in the collection.
  • Process the fields in each record.

The following example writes the values from table for objId to the console.

Dim fieldDefs As ObjectData.FieldDefinitions = _
  table.FieldDefinitions
Dim recs As ObjectData.Records
recs = table.GetObjectTableRecords(0, objId, _
  Constants.OpenMode.OpenForRead, True)
 
If (recs.Count() > 0) Then
   For Each rec As ObjectData.Record In recs
      For i As Integer = 0 To rec.Count() - 1
         Dim val As Autodesk.Gis.Map.Utilities.MapValue
         val = rec(i)
         Dim fieldDef As ObjectData.FieldDefinition
         fieldDef = fieldDefs(i)
         acEditor.WriteMessage(
           vbNewLine + fieldDef.Name + ": ")
         Select Case val.Type
            Case Constants.DataType.Character
               acEditor.WriteMessage(val.StrValue)
            Case Constants.DataType.Integer
               acEditor.WriteMessage(val.Int32Value.ToString)
            Case Constants.DataType.Point
               acEditor.WriteMessage("point")
            Case Constants.DataType.Real
               acEditor.WriteMessage(val.DoubleValue.ToString)
            Case Else
               acEditor.WriteMessage("undefined")
         End Select
      Next
   Next
End If
recs.Dispose()

Processing all tables for an object is similar. Instead of calling Table.GetObjectTableRecords() for an individual table, call Tables.GetObjectRecords() for all tables. When processing the fields, be sure to to get the field definitions from the correct table for the current record.

  • Get the ObjectData.Tables object for the drawing.
  • Get the ObjectData.Records collection for the object, using one of the GetObjectRecords() methods.
  • Iterate through the records in the collection.
  • Get the table name for the current record.
  • Get the fields definitions for the table.
  • Process the fields in each record.
NoteWhen you have finished processing the records, release any of the disposable objects with their Dispose() methods. This applies to any classes inheriting Autodesk.AutoCAD.Runtime.DisposableWrapper, like ObjectData.Table, ObjectData.Records, or Utilities.MapValue.