Erasing all objects

Erasing all objects

Anonymous
Not applicable
526 Views
2 Replies
Message 1 of 3

Erasing all objects

Anonymous
Not applicable
Is there an easy way to erase/remove all objects on a drawing via .NET? I can remove simple objects (i.e. polylines) with a simple iteration and obj.Erase, but this technique does not work with Block Defs/Refs.

Thanks

Paul Edited by: paulep on Mar 30, 2010 8:04 PM
0 Likes
527 Views
2 Replies
Replies (2)
Message 2 of 3

arcticad
Advisor
Advisor
This will erase all the blocks in the blocks definitions
of the current drawing.

{code}
Public Sub eraseBlockDefinitions()

' get Local Drawing
Using db As Database = HostApplicationServices.WorkingDatabase()
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Using lock As DocumentLock = dwg.LockDocument
Using BT As BlockTable = dwg.Database.BlockTableId.GetObject(OpenMode.ForRead)
Using BTE As SymbolTableEnumerator = BT.GetEnumerator
' step through block definitions
While BTE.MoveNext = True
Try
Using myBTR As BlockTableRecord = BTE.Current.GetObject(OpenMode.ForWrite)

If Not myBTR.IsErased Then
' remove if you want to delete references also
If Not (myBTR.IsFromExternalReference Or myBTR.IsFromOverlayReference) Then
If Not myBTR.IsLayout Then
myBTR.Erase()
End If
End If
End If
End Using
Catch ex As Exception
' msgbox("Something is wrong" & ex.tostring)
End Try
End While
' Commit changes
tr.Commit()
End Using
End Using
End Using
End Using
End Using
' Update Drawing View
regen()
End Sub

Sub regen()
Dim MyDWG As Autodesk.AutoCAD.ApplicationServices.Document
MyDWG = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim MyEd As EditorInput.Editor
MyEd = MyDWG.Editor
MyEd.Regen()
End Sub
{code}
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thanks so much. I also collected the ids for a final ReclaimMemoryFromErasedObjects. This was to avoid getting an error when blocks of the same name were inserted later.

Paul
0 Likes