<?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: Purging in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/purging/m-p/2618696#M67466</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
This will purge all non referenced materials&lt;BR /&gt;
&lt;BR /&gt;
{code}ObjectIdCollection ids = new ObjectIdCollection();&lt;BR /&gt;
using (Transaction tr = db.TransactionManager.StartTransaction())&lt;BR /&gt;
{&lt;BR /&gt;
    DBDictionary matDict = (DBDictionary)tr.GetObject(db.MaterialDictionaryId, OpenMode.ForRead, false);&lt;BR /&gt;
    foreach (DBDictionaryEntry entry in matDict)&lt;BR /&gt;
    {&lt;BR /&gt;
        string key = entry.Key;&lt;BR /&gt;
        if ((key != "ByBlock") &amp;amp;&amp;amp; (key != "ByLayer") &amp;amp;&amp;amp; (key != "Global"))&lt;BR /&gt;
            ids.Add(entry.Value);&lt;BR /&gt;
    }&lt;BR /&gt;
    db.Purge(ids);&lt;BR /&gt;
    foreach (ObjectId id in ids)&lt;BR /&gt;
    {&lt;BR /&gt;
        DBObject obj = (DBObject)tr.GetObject(id, OpenMode.ForWrite);&lt;BR /&gt;
        obj.Erase();&lt;BR /&gt;
    }&lt;BR /&gt;
        tr.Commit();&lt;BR /&gt;
}{code}

Edited by: _gile on Jan 19, 2010 1:28 PM</description>
    <pubDate>Tue, 19 Jan 2010 12:27:50 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2010-01-19T12:27:50Z</dc:date>
    <item>
      <title>Purging</title>
      <link>https://forums.autodesk.com/t5/net-forum/purging/m-p/2618695#M67465</link>
      <description>Need a bit of help with purging materials from a drawing. I have managed to purge all items within a named object table like layers and blocks but those in the Named Object dictionary table are confusing me a little. &lt;BR /&gt;
&lt;BR /&gt;
Do I need to itterate through the named objects dictionarys to get the AEC_MATERIAL_DEFS dictionary then purge the contents from there?&lt;BR /&gt;
&lt;BR /&gt;
Thanks for any help.&lt;BR /&gt;
Daniel</description>
      <pubDate>Tue, 19 Jan 2010 11:56:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/purging/m-p/2618695#M67465</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-19T11:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Purging</title>
      <link>https://forums.autodesk.com/t5/net-forum/purging/m-p/2618696#M67466</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
This will purge all non referenced materials&lt;BR /&gt;
&lt;BR /&gt;
{code}ObjectIdCollection ids = new ObjectIdCollection();&lt;BR /&gt;
using (Transaction tr = db.TransactionManager.StartTransaction())&lt;BR /&gt;
{&lt;BR /&gt;
    DBDictionary matDict = (DBDictionary)tr.GetObject(db.MaterialDictionaryId, OpenMode.ForRead, false);&lt;BR /&gt;
    foreach (DBDictionaryEntry entry in matDict)&lt;BR /&gt;
    {&lt;BR /&gt;
        string key = entry.Key;&lt;BR /&gt;
        if ((key != "ByBlock") &amp;amp;&amp;amp; (key != "ByLayer") &amp;amp;&amp;amp; (key != "Global"))&lt;BR /&gt;
            ids.Add(entry.Value);&lt;BR /&gt;
    }&lt;BR /&gt;
    db.Purge(ids);&lt;BR /&gt;
    foreach (ObjectId id in ids)&lt;BR /&gt;
    {&lt;BR /&gt;
        DBObject obj = (DBObject)tr.GetObject(id, OpenMode.ForWrite);&lt;BR /&gt;
        obj.Erase();&lt;BR /&gt;
    }&lt;BR /&gt;
        tr.Commit();&lt;BR /&gt;
}{code}

Edited by: _gile on Jan 19, 2010 1:28 PM</description>
      <pubDate>Tue, 19 Jan 2010 12:27:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/purging/m-p/2618696#M67466</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2010-01-19T12:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Purging</title>
      <link>https://forums.autodesk.com/t5/net-forum/purging/m-p/2618697#M67467</link>
      <description>I see, you can directly access the materialdictionaryID - I thought it would need itterating through each named dictionary to find the materials dictionary.&lt;BR /&gt;
&lt;BR /&gt;
Thanks Gile.</description>
      <pubDate>Tue, 19 Jan 2010 12:33:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/purging/m-p/2618697#M67467</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-19T12:33:36Z</dc:date>
    </item>
  </channel>
</rss>

