<?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: Programmatically refresh layer usage information .NET in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2795326#M63523</link>
    <description>&lt;P&gt;I tried calling GenerateUsageData before doing a foreach loop on the LayerTable but it still didn't return all the layers.&lt;/P&gt;</description>
    <pubDate>Wed, 13 Oct 2010 13:31:56 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-10-13T13:31:56Z</dc:date>
    <item>
      <title>Programmatically refresh layer usage information .NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2794756#M63521</link>
      <description>&lt;P&gt;In C# I noticed that when I loop through the LayerTableRecords in the LayerTable some of the layers in the drawing do not show up.&amp;nbsp; If I look at the layers in the UI it shows the missing layers with a grey icon for their status while the ones that it does detect have a blue icon for their status.&amp;nbsp; The status has to do with which layers that the drawing believes are in use.&amp;nbsp; In the UI you can press a refresh button and this will fix the problem.&amp;nbsp; I want to know how I can fix this through the .NET API, COM API, or command line.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2010 20:03:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2794756#M63521</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-12T20:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically refresh layer usage information .NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2794812#M63522</link>
      <description>&lt;P&gt;Have not tested it but have you tried the LayerTable method GenerateUsageData&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2010 20:43:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2794812#M63522</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-12T20:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically refresh layer usage information .NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2795326#M63523</link>
      <description>&lt;P&gt;I tried calling GenerateUsageData before doing a foreach loop on the LayerTable but it still didn't return all the layers.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2010 13:31:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2795326#M63523</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-13T13:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically refresh layer usage information .NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2795566#M63524</link>
      <description>&lt;P&gt;Another thing that I noticed is that this problem only occurs when I open the database using Database.ReadDwgFile.&amp;nbsp; If I first open the drawing using Application.DocumentManager.Open and then get the database from MdiActiveDocument then all of the layers show up correctly.&amp;nbsp; I would open the drawing but it is much faster to alter the database.&amp;nbsp; All that I'm doing is setting Freeze/On/Locked on the layers.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2010 15:53:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2795566#M63524</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-13T15:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically refresh layer usage information .NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2795648#M63525</link>
      <description>&lt;P&gt;Can you post your code that would help alot for helping you out.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2010 17:03:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2795648#M63525</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-13T17:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically refresh layer usage information .NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2795680#M63526</link>
      <description>&lt;P&gt;The following shows two examples of enumerating through the layers.&amp;nbsp; The second option will work, but I as I said earlier I do not want to open the drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code for just opening the database:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using (Database database = new Database(false, true))
        {
          database.ReadDwgFile(drawingFilePath, FileShare.ReadWrite, true, String.Empty);

          using (Transaction transaction = database.TransactionManager.StartTransaction())
          {
            LayerTable layerTable = transaction.GetObject(database.LayerTableId, OpenMode.ForWrite) as LayerTable;
            database.Clayer = database.LayerZero;
            
            foreach (ObjectId layerID in layerTable)
            {
              LayerTableRecord layer = (LayerTableRecord)transaction.GetObject(layerID, OpenMode.ForWrite);

              //Do something to layer
            }

            transaction.Commit();
          }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code when opening the drawing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Application.DocumentManager.Open(drawingFilePath, false);

      Document document = Application.DocumentManager.MdiActiveDocument;
      Database database = document.Database;
      DocumentLock documentLock = document.LockDocument(DocumentLockMode.Write, null, null, true);

      using (documentLock)
      {
        using (Transaction transaction = database.TransactionManager.StartTransaction())
        {
          LayerTable layerTable = transaction.GetObject(database.LayerTableId, OpenMode.ForWrite) as LayerTable;

          database.Clayer = database.LayerZero;

          foreach (ObjectId layerID in layerTable)
          {
            LayerTableRecord layer = (LayerTableRecord)transaction.GetObject(layerID, OpenMode.ForWrite);

            //Do something to layer
          }
        }
      }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2010 17:25:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2795680#M63526</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-13T17:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically refresh layer usage information .NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2800566#M63527</link>
      <description>&lt;P&gt;It seems that the problem was that one of the entities in the particular drawing was corrupt. When one of the users recreated the drawing (including re-adding some xrefs) and ran the program it worked just fine. I also double checked the code and it was definitely hitting the correct layers this time. I am however open to suggestions or solutions on how to detect corruption problems in AutoCAD drawings.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2010 12:47:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/2800566#M63527</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-10-19T12:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically refresh layer usage information .NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/3920780#M63528</link>
      <description>&lt;P&gt;Exactly the same issue hasn't been solved in ACAD2012. I tried to Audit and recover my dwg file and found nothing corrupted. How many years needed to solve it?&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2013 23:07:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/programmatically-refresh-layer-usage-information-net/m-p/3920780#M63528</guid>
      <dc:creator>harryliu3140</dc:creator>
      <dc:date>2013-05-13T23:07:41Z</dc:date>
    </item>
  </channel>
</rss>

