- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a form that all the object data gets imported into when I select a parcel. I want to be able to edit the data and overwrite the object data in my drawing.
Using the code below when I hit the button and select the parcel I want to overwrite the data to, it attaches a duplicate table with the same name to the entity and all the data is empty except for the owners name. What do I need to change to make it just overwrite the existing table without creating a duplicate one.
Private Sub updateOD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updateOD.Click
Dim id As ObjectId '= myid
Dim doc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim trans As Transaction = db.TransactionManager.StartTransaction()
Dim odTable As Autodesk.Gis.Map.ObjectData.Table
Dim odTables As Autodesk.Gis.Map.ObjectData.Tables
odTables = HostMapApplicationServices.Application.ActiveProject.ODTables
Try
Dim ed As Autodesk.AutoCAD.EditorInput.Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Using docloc As DocumentLock = doc.LockDocument
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("All_Parcels")
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(3)
mapVal.Assign(OwnerName.Text)
' dbObj should be opened for Write, otherwise
odTable.AddRecord(odRecord, dbObj)
odRecord.Dispose()
odrecords.Dispose()
trans.Commit()
End Using
Catch exc As Autodesk.Gis.Map.MapException
MsgBox("Error : " + exc.Message.ToString())
End Try
End Sub
End Class
Solved! Go to Solution.