PDA

View Full Version : Deleting Objects (eNotOpenForWrite error)



bweir
2007-01-15, 04:19 PM
I'm working on a function to delete drawing objects on different layers. This routine uses the database of a drawing and is loaded using the database.ReadDwgFile.

The code goes something like this...


Dim Block As Autodesk.AutoCAD.Interop.Common.AcadBlockReference
Dim ObjId As Autodesk.AutoCAD.DatabaseServices.ObjectId
Dim AcadEnt As Autodesk.AutoCAD.Interop.Common.AcadEntity

For Each ObjId In Blocks.AcadObject
Block = Trans.GetObject(ObjId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite, True, True)

For Each AcadEnt In Block.AcadObject
If AcadEnt.Layer = "Layer to remove" Then AcadEnt.Delete()
Next
Next

The drawing is saved using the database.SaveAs method and everything goes great until... When I try to open the newly created drawing I get an eNotOpenForWrite error message. I believe AutoCAD is seeing pointers for the erased objects but cannot open them because the objects are of course erased. How can I make sure that this error does not occur? I thought the database.AutoDelete property (which is set to True) took care of removing the pointers but I'm still having the eNotOpenForWrite error pop up.

What should I use to erase to objects?

bweir
2007-01-15, 05:13 PM
Found out what was wrong. It wasn't actually the code at all. There was a problem with a drawing file. By using the AUDIT command we where able to fix the drawing. The program then worked perfectly and the copied drawing didn't have a single error. :D