.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Erasing all objects

2 REPLIES 2
Reply
Message 1 of 3
paulep
393 Views, 2 Replies

Erasing all objects

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
2 REPLIES 2
Message 2 of 3
arcticad
in reply to: paulep

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))
Message 3 of 3
paulep
in reply to: paulep

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost