Many a times you want to add Object Data to entities in DWG file using Map 3D API. Using Map 3D C++ API or .NET API we can add object data to entities. Here is a VB.NET code snippet which shows how to add Object Data to a selected entity in AutoCAD Map 3D. One thing to note here - when you use AddRecord(record As Autodesk.Gis.Map.ObjectData.Record, dbObj As Autodesk.AutoCAD.DatabaseServices.DBObject) make sure that DBObject is open for write, otherwise you are likely to see an exception message.
Try
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim prompt_result As PromptEntityResult = ed.GetEntity(vbCrLf + "Select the object...")
id = prompt_result.ObjectId
Dim dbObj As DBObject = trans.GetObject(id, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
'' Presuming OD Table "MyTestODTable" exist in the DWG file
odTable = odTables.Item("MyTestODTable")
Dim odrecords As ObjectData.Records = odTable.GetObjectTableRecords(Convert.ToUInt32(0), id, Constants.OpenMode.OpenForRead, False)
Dim odRecord As ObjectData.Record = odrecords.Item(0)
odRecord = Autodesk.Gis.Map.ObjectData.Record.Create()
odTable.InitRecord(odRecord)
Dim mapVal As Autodesk.Gis.Map.Utilities.MapValue
'' Add a Record and assign a value to it
mapVal = odRecord(0)
mapVal.Assign("Test")
mapVal = odRecord(1)
mapVal.Assign(22)
' dbObj should be opened for Write, otherwise
odTable.AddRecord(odRecord, dbObj)
odRecord.Dispose()
odrecords.Dispose()
trans.Commit()
Catch exc As Autodesk.Gis.Map.MapException
MsgBox("Error : " + exc.Message.ToString())
End Try
And here is the result :