<?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: How to purge useless blocks generated by importing sidedb, anonymous blocks in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-purge-useless-blocks-generated-by-importing-sidedb/m-p/12636886#M5060</link>
    <description>&lt;P&gt;ActivistInvestor,&lt;BR /&gt;thanks for your reply.&lt;BR /&gt;I found that blocktablerecord was cleared after running the following code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;    public static ObjectIdCollection GetCanPurgeObjectids(this Database db)
    {
      using (Transaction tr = new OpenCloseTransaction())
      {
        ObjectIdCollection idsA = new ObjectIdCollection();
        var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
        ObjectIdCollection ids;

        while (true)
        {
          ids = new ObjectIdCollection(bt.Cast&amp;lt;ObjectId&amp;gt;().ToArray());

          db.Purge(ids);
          if (ids.Count == 0)
            break;
          for (int i = 0; i &amp;lt; ids.Count; i++)
          {
            var obj = tr.GetObject(ids[i], OpenMode.ForWrite, false, true);
            obj.Erase(false);
            idsA.Add(ids[i]);
          }
          ids.Clear();
        }
        tr.Commit();
        return idsA;
      }
    }

&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 13 Mar 2024 05:59:02 GMT</pubDate>
    <dc:creator>swaywood</dc:creator>
    <dc:date>2024-03-13T05:59:02Z</dc:date>
    <item>
      <title>How to purge useless blocks generated by importing sidedb, anonymous blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-purge-useless-blocks-generated-by-importing-sidedb/m-p/12636769#M5058</link>
      <description>&lt;P&gt;Hello,my question is like this.&lt;BR /&gt;Inserting sidedb into the current drawing will import many useless blocks, anonymous blocks, etc&lt;BR /&gt;I want to precisely purge all of these now,&lt;/P&gt;&lt;P&gt;but I need to keep all the blocks before inserting action.&lt;/P&gt;&lt;P&gt;I have some code, but it will purge all the blocks.&lt;/P&gt;&lt;P&gt;I see a method&lt;BR /&gt;Public void Purge (ObjectidGraph idGraph);&lt;BR /&gt;But I don't know how to use it to achieve my goal.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;    public static void PurgeBlock(this Database db)
    {
      string sLine = db.OriginalFileName;
      using (var tr = db.TransactionManager.StartTransaction())
      {
        try
        {
          #region 块
          var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
          ObjectIdCollection idsBt;
          do
          {
            idsBt = new ObjectIdCollection(bt.Cast&amp;lt;ObjectId&amp;gt;().ToArray());
            db.Purge(idsBt);
            foreach (ObjectId id in idsBt)
            {
              tr.GetObject(id, OpenMode.ForWrite).Erase();
            }
          } while (0 &amp;lt; idsBt.Count);
          #endregion 块        
        }
        catch (SystemException ex1)
        {
          string message = string.Format("错误名称：【{0}】\nStackTrace：【{1}】\n：TargetSite【{2}】\n【{3}】",
            ex1.Message, ex1.StackTrace.ToString(), ex1.TargetSite.ToString(), sLine);
          TestHelper.AddError(message);
        }
        catch (Runtime.Exception ex2)
        {
          string message = string.Format("错误名称：【{0}】\nStackTrace：【{1}】\n：TargetSite【{2}】,【{3}】",
            ex2.Message, ex2.StackTrace.ToString(), ex2.TargetSite.ToString(), sLine);
          TestHelper.AddError(message);
        }
        tr.Commit();
      }
    }&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 13 Mar 2024 04:22:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-purge-useless-blocks-generated-by-importing-sidedb/m-p/12636769#M5058</guid>
      <dc:creator>swaywood</dc:creator>
      <dc:date>2024-03-13T04:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to purge useless blocks generated by importing sidedb, anonymous blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-purge-useless-blocks-generated-by-importing-sidedb/m-p/12636788#M5059</link>
      <description>&lt;P&gt;You can use the overload of Purge() that takes an ObjectIdCollection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That method doesn't actually purge anything, it simply returns the ObjectIds of objects that can be purged (e.g., the same ones the Purge command would allow you to purge).&amp;nbsp; You just need to erase them, and that's it. You may need to call the method multiple times, because erasing some objects can cause other objects to become unreferenced. The other method that takes an ObjectIdGraph can be used to do it in a single pass, by traversing the graph and erasing objects along the way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;   public static class Purger
   {
      public static int PurgeAll()
      {
         using(Transaction tr = new OpenCloseTransaction())
         {
            Database db = HostApplicationServices.WorkingDatabase;
            ObjectIdCollection ids = new ObjectIdCollection();
            int count = 0;
            while(true)
            {
               db.Purge(ids);
               if(ids.Count == 0)
                  break;
               count += ids.Count;
               for(int i = 0; i &amp;lt; ids.Count; i++)
               {
                  var obj = tr.GetObject(ids[i], OpenMode.ForWrite, false, true);
                  obj.Erase(true);
               }
               ids.Clear();
            }
            tr.Commit();
            return count;
         }
      }
   }&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 13 Mar 2024 04:57:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-purge-useless-blocks-generated-by-importing-sidedb/m-p/12636788#M5059</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-03-13T04:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to purge useless blocks generated by importing sidedb, anonymous blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-purge-useless-blocks-generated-by-importing-sidedb/m-p/12636886#M5060</link>
      <description>&lt;P&gt;ActivistInvestor,&lt;BR /&gt;thanks for your reply.&lt;BR /&gt;I found that blocktablerecord was cleared after running the following code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;    public static ObjectIdCollection GetCanPurgeObjectids(this Database db)
    {
      using (Transaction tr = new OpenCloseTransaction())
      {
        ObjectIdCollection idsA = new ObjectIdCollection();
        var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
        ObjectIdCollection ids;

        while (true)
        {
          ids = new ObjectIdCollection(bt.Cast&amp;lt;ObjectId&amp;gt;().ToArray());

          db.Purge(ids);
          if (ids.Count == 0)
            break;
          for (int i = 0; i &amp;lt; ids.Count; i++)
          {
            var obj = tr.GetObject(ids[i], OpenMode.ForWrite, false, true);
            obj.Erase(false);
            idsA.Add(ids[i]);
          }
          ids.Clear();
        }
        tr.Commit();
        return idsA;
      }
    }

&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 13 Mar 2024 05:59:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-purge-useless-blocks-generated-by-importing-sidedb/m-p/12636886#M5060</guid>
      <dc:creator>swaywood</dc:creator>
      <dc:date>2024-03-13T05:59:02Z</dc:date>
    </item>
    <item>
      <title>回复： How to purge useless blocks generated by importing sidedb, anonymous blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-purge-useless-blocks-generated-by-importing-sidedb/m-p/12636902#M5061</link>
      <description>&lt;P&gt;I got it,&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;just don't submit it&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 06:07:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-purge-useless-blocks-generated-by-importing-sidedb/m-p/12636902#M5061</guid>
      <dc:creator>swaywood</dc:creator>
      <dc:date>2024-03-13T06:07:28Z</dc:date>
    </item>
  </channel>
</rss>

