Removing Object Data from an Entity using Map 3D API

By Partha Sarkar

Often I come across the following question: I want to remove Object Data from an entity in a DWG file and I have hundreds of such entities in that file. Is there an easy way using API I could do this?

Answer is 'Yes' and we need to use Autodesk.Gis.Map.ObjectData.Records.RemoveRecord() to do this. 
Here is a VB.NET code snippet which shows how to remove Object Data from a selected entity in AutoCAD Map 3D:

Try            
      Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
      Dim opSelect As New PromptSelectionOptions()
      Dim rsSelect As PromptSelectionResult
      Dim dbObj As DBObject
      rsSelect = ed.GetSelection(opSelect)
      If rsSelect.Status  PromptStatus.OK Then
          MsgBox("fail")
          Exit Sub
      End If
      Dim idCols As New ObjectIdCollection(rsSelect.Value.GetObjectIds())
      Dim id As ObjectId
      For Each id In idCols
 
          dbObj = trans.GetObject(id, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
 
          '' Presuming OD Table "MyTestODTable" exist in the DWG file  
          Dim myTable As Autodesk.Gis.Map.ObjectData.Table  = odTables("MyTestODTable")
 
          Using recs As Records = myTable.GetObjectTableRecords(0, dbObj, Constants.OpenMode.OpenForWrite, True)
            Dim ie As IEnumerator = recs.GetEnumerator()
            Do While ie.MoveNext()
                recs.RemoveRecord()
            Loop
          End Using
      Next
 
      trans.Commit()
 
  Catch exc As Autodesk.Gis.Map.MapException           
      MsgBox("Error : " + exc.Message.ToString())   
  End Try

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading