1

Found this out on my own after finding some stuff online. Took me a while but for anyone who wants to know how to do it see below. Also, the code I posted had a big problem with it acText was never declared in it. I was also setting it equal to acadObj incorrectly. It needed to be set on a case to case basis. Below is the delete code I have. It has something to do with opening the working database editor.

Public Sub deleteDBObject(ByRef dbObj As DBObject)
    Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
    Dim db As Database = HostApplicationServices.WorkingDatabase
    Dim tm As Transaction = db.TransactionManager.StartTransaction()
    Try
        Dim ent As Entity = CType(tm.GetObject(dbObj.Id, OpenMode.ForWrite), Entity)
        ent.Erase()
        ent = Nothing
        dbObj = Nothing
        tm.Commit()
    Catch
    Finally
        tm.Dispose()
    End Try
    Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen()
End Sub

If Anyone knows how to do it a better way or if they can explain why this works that would be hot.

IByrd
  • 177
  • 1
  • 13
  • Update on this. This is the easiest and dirtiest way in my opinion of deleting an ACAD DBObject. However I have found that setting them to just not be visible is a much better way of handling the DBObjects in code. However you have to treat them as memory leaks at that point because although their invisible data about them still exists in ACAD. I would still like a "cleaner" way of deleting objects in ACAD through VB.NET but I have had no such luck finding a way. I am starting a bounty on this. – IByrd Feb 18 '15 at 18:06

1 Answers1

1

Sorry, but I don't understand. Since you already have a DBObject(dbObj), if it is a database resident object, call its Erase method (dbObj.Erase()); if it is not, just leave it alone and gc of .NET Framework will handle it.

  • So your saying if I erase this and create a new vb object and commit the new one to the database in AutoCAD the only thing in memory will be the newly created dbobject. Would AutoCAD have it in its database, meaning will it be saved when I save the new drawing? – IByrd Feb 28 '15 at 07:09
  • The newly created object will be saved to the drawing, while the erased one would not. – Arphone Pei Mar 02 '15 at 01:20
  • Okay cool. haha I really don't know much about ACAD just starting. So this is good news. – IByrd Mar 02 '15 at 15:04