Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
When I try to delete a block I get this error:
---------------------------
AutoCAD Error Aborting
---------------------------
INTERNAL ERROR: !dbobji.cpp@8638: eNotOpenForWrite
---------------------------
What is happenening? I have my tables opened for Write.
Here is the code Im using:
<CommandMethod("CleanHouse")> Sub CleanHouse() Dim OldBlocks() As String = {"MyOldBlock1","OldBlock2"} Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor 'get object id's of all block in the active drawing Dim objIdColl As ObjectIdCollection = BlockReferenceInModelSpace(ed) 'lock document Dim docLock As DocumentLock = doc.LockDocument 'start transaction Dim tx As Transaction = db.TransactionManager.StartTransaction 'iterate object id For Each objId As ObjectId In objIdColl 'get the obeject Dim ent As Entity = tx.GetObject(objId, OpenMode.ForWrite) If (TypeOf ent Is BlockReference) Then 'casting block reference Dim br As BlockReference = CType(ent, BlockReference) '~ Loop Thru the Defined Borders For x = LBound(OldBlocks) To UBound(OldBlocks) '~ Check if the block is in the block table Dim acBlkTbl As BlockTable acBlkTbl = tx.GetObject(db.BlockTableId, OpenMode.ForWrite) If acBlkTbl.Has(OldBlocks(x)) Then 'Loop thru all the blocks For Each blk In acBlkTbl ''now check the block name here If (br.Name = OldBlocks(x)) Then br.Erase(True) tx.Commit() End If Next End If Next x End If Next objId End Sub
Solved! Go to Solution.