Attaching Object Data

AutoCAD Map 3D .NET API

 
Attaching Object Data
 
 
 

Adding object data to a drawing object requires:

  • Creating an empty record
  • Initializing the record with correct types for the table
  • Setting values for each column
  • Attaching the object data by adding the record to the table

Create an empty record using the static method ObjectData.Record.Create(). This does not define any fields for the record. Initialize the record, which creates fields of the correct type, using Table.InitRecord().

Dim rec As ObjectData.Record
rec = ObjectData.Record.Create()
table.InitRecord(rec)

Each Item property in the record is of type Utilities.MapValue, which is a general-purpose class for storing data of variant types. To set any field, get a reference to the field from the Record object using the Item property. Assign the value with MapValue.Assign(). For example, if rec is a record in a table where the second field is of type integer, the following will assign a value of 10 to the field.

Dim val As Utilities.MapValue
val = rec(1)
val.Assign(10)

Add the record to the table with Table.AddRecord() and associate it with an object. This requires a Record and either an AutoCAD DBObject or ObjectId as parameters.

newTable.AddRecord(rec, objId)

A single drawing object may have more than one object data record in a given table.