<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Erasing all objects in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/erasing-all-objects/m-p/2657796#M66175</link>
    <description>This will erase all the blocks in the blocks definitions&lt;BR /&gt;
of the current drawing.&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
 Public Sub eraseBlockDefinitions()&lt;BR /&gt;
&lt;BR /&gt;
        ' get Local Drawing&lt;BR /&gt;
        Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
            Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;
                Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
                Using lock As DocumentLock = dwg.LockDocument&lt;BR /&gt;
                    Using BT As BlockTable = dwg.Database.BlockTableId.GetObject(OpenMode.ForRead)&lt;BR /&gt;
                        Using BTE As SymbolTableEnumerator = BT.GetEnumerator&lt;BR /&gt;
                            ' step through block definitions&lt;BR /&gt;
                            While BTE.MoveNext = True&lt;BR /&gt;
                                Try&lt;BR /&gt;
                                    Using myBTR As BlockTableRecord = BTE.Current.GetObject(OpenMode.ForWrite)&lt;BR /&gt;
&lt;BR /&gt;
                                        If Not myBTR.IsErased Then&lt;BR /&gt;
                                            ' remove if you want to delete references also&lt;BR /&gt;
                                            If Not (myBTR.IsFromExternalReference Or myBTR.IsFromOverlayReference) Then&lt;BR /&gt;
                                                If Not myBTR.IsLayout Then&lt;BR /&gt;
                                                    myBTR.Erase()&lt;BR /&gt;
                                                End If&lt;BR /&gt;
                                            End If&lt;BR /&gt;
                                        End If&lt;BR /&gt;
                                    End Using&lt;BR /&gt;
                                Catch ex As Exception&lt;BR /&gt;
                                    ' msgbox("Something is wrong" &amp;amp; ex.tostring)&lt;BR /&gt;
                                End Try&lt;BR /&gt;
                            End While&lt;BR /&gt;
                            ' Commit changes&lt;BR /&gt;
                            tr.Commit()&lt;BR /&gt;
                        End Using&lt;BR /&gt;
                    End Using&lt;BR /&gt;
                End Using&lt;BR /&gt;
            End Using&lt;BR /&gt;
        End Using&lt;BR /&gt;
        ' Update Drawing View&lt;BR /&gt;
        regen()&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub regen()&lt;BR /&gt;
        Dim MyDWG As Autodesk.AutoCAD.ApplicationServices.Document&lt;BR /&gt;
        MyDWG = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim MyEd As EditorInput.Editor&lt;BR /&gt;
        MyEd = MyDWG.Editor&lt;BR /&gt;
        MyEd.Regen()&lt;BR /&gt;
    End Sub&lt;BR /&gt;
{code}</description>
    <pubDate>Tue, 30 Mar 2010 20:27:02 GMT</pubDate>
    <dc:creator>arcticad</dc:creator>
    <dc:date>2010-03-30T20:27:02Z</dc:date>
    <item>
      <title>Erasing all objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/erasing-all-objects/m-p/2657795#M66174</link>
      <description>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.&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Paul

Edited by: paulep on Mar 30, 2010 8:04 PM</description>
      <pubDate>Tue, 30 Mar 2010 19:08:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erasing-all-objects/m-p/2657795#M66174</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-03-30T19:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Erasing all objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/erasing-all-objects/m-p/2657796#M66175</link>
      <description>This will erase all the blocks in the blocks definitions&lt;BR /&gt;
of the current drawing.&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
 Public Sub eraseBlockDefinitions()&lt;BR /&gt;
&lt;BR /&gt;
        ' get Local Drawing&lt;BR /&gt;
        Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
            Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;
                Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
                Using lock As DocumentLock = dwg.LockDocument&lt;BR /&gt;
                    Using BT As BlockTable = dwg.Database.BlockTableId.GetObject(OpenMode.ForRead)&lt;BR /&gt;
                        Using BTE As SymbolTableEnumerator = BT.GetEnumerator&lt;BR /&gt;
                            ' step through block definitions&lt;BR /&gt;
                            While BTE.MoveNext = True&lt;BR /&gt;
                                Try&lt;BR /&gt;
                                    Using myBTR As BlockTableRecord = BTE.Current.GetObject(OpenMode.ForWrite)&lt;BR /&gt;
&lt;BR /&gt;
                                        If Not myBTR.IsErased Then&lt;BR /&gt;
                                            ' remove if you want to delete references also&lt;BR /&gt;
                                            If Not (myBTR.IsFromExternalReference Or myBTR.IsFromOverlayReference) Then&lt;BR /&gt;
                                                If Not myBTR.IsLayout Then&lt;BR /&gt;
                                                    myBTR.Erase()&lt;BR /&gt;
                                                End If&lt;BR /&gt;
                                            End If&lt;BR /&gt;
                                        End If&lt;BR /&gt;
                                    End Using&lt;BR /&gt;
                                Catch ex As Exception&lt;BR /&gt;
                                    ' msgbox("Something is wrong" &amp;amp; ex.tostring)&lt;BR /&gt;
                                End Try&lt;BR /&gt;
                            End While&lt;BR /&gt;
                            ' Commit changes&lt;BR /&gt;
                            tr.Commit()&lt;BR /&gt;
                        End Using&lt;BR /&gt;
                    End Using&lt;BR /&gt;
                End Using&lt;BR /&gt;
            End Using&lt;BR /&gt;
        End Using&lt;BR /&gt;
        ' Update Drawing View&lt;BR /&gt;
        regen()&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub regen()&lt;BR /&gt;
        Dim MyDWG As Autodesk.AutoCAD.ApplicationServices.Document&lt;BR /&gt;
        MyDWG = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim MyEd As EditorInput.Editor&lt;BR /&gt;
        MyEd = MyDWG.Editor&lt;BR /&gt;
        MyEd.Regen()&lt;BR /&gt;
    End Sub&lt;BR /&gt;
{code}</description>
      <pubDate>Tue, 30 Mar 2010 20:27:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erasing-all-objects/m-p/2657796#M66175</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2010-03-30T20:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Erasing all objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/erasing-all-objects/m-p/2657797#M66176</link>
      <description>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.&lt;BR /&gt;
&lt;BR /&gt;
Paul</description>
      <pubDate>Wed, 31 Mar 2010 12:39:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erasing-all-objects/m-p/2657797#M66176</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-03-31T12:39:53Z</dc:date>
    </item>
  </channel>
</rss>

