<?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 I want in C#, count the number of layers included in the current file. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10164671#M17163</link>
    <description>&lt;P&gt;Hello , i want to create a function that count the number of layer in my current file .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                
                string num = no_folio.ToString();
               
                foreach(var clq in calques)
                {
                   
                   LayerTableRecord clqr = tr.GetObject(clq,OpenMode.ForRead) as LayerTableRecord;
                   
                }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but i don't know ,how i can count the number of layer or get the number of layer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks a lot &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Mar 2021 16:51:49 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-03-17T16:51:49Z</dc:date>
    <item>
      <title>I want in C#, count the number of layers included in the current file.</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10164671#M17163</link>
      <description>&lt;P&gt;Hello , i want to create a function that count the number of layer in my current file .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                
                string num = no_folio.ToString();
               
                foreach(var clq in calques)
                {
                   
                   LayerTableRecord clqr = tr.GetObject(clq,OpenMode.ForRead) as LayerTableRecord;
                   
                }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but i don't know ,how i can count the number of layer or get the number of layer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks a lot &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 16:51:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10164671#M17163</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-17T16:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: I want in C#, count the number of layers included in the current file.</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10164883#M17164</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You can simply use a counter in your foreach loop:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;int nombreCalques = 0;
foreach(ObjectId id in calques)
{
    var clqr = (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead);
    nombreCalques++;           
}&lt;/LI-CODE&gt;
&lt;P&gt;Or use Linq:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;calques.Cast&amp;lt;ObjectId&amp;gt;().Count();&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 17 Mar 2021 18:01:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10164883#M17164</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-03-17T18:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: I want in C#, count the number of layers included in the current file.</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10166709#M17165</link>
      <description>&lt;P&gt;Bonjour Gilles,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tout d'abord je tiens à vous remercier pour la réponse apporter et pour tout vos cours en ligne,&lt;/P&gt;&lt;P&gt;Je suis alternant et cela m'a beaucoup aidé.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pour revenir au code , j'ai bien une réponse correcte,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ce que je souhaite faire en réalité, c'est mettre une condition : Empêchant le lancement du code si nous avons des calques numéroté qui sont supérieur à 2,je ne veux pas prendre en compte les calques qui sont nommés par des chaînes de caractères.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Remerciements,&lt;/P&gt;&lt;P&gt;Armand &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 10:29:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10166709#M17165</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-18T10:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: I want in C#, count the number of layers included in the current file.</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10166779#M17166</link>
      <description>&lt;P&gt;La demande n'est pas claire.&lt;/P&gt;
&lt;P&gt;S'agit-il de traiter uniquement les calques nommés "0" ou "1" ?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 10:46:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10166779#M17166</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-03-18T10:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: I want in C#, count the number of layers included in the current file.</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10166790#M17167</link>
      <description>&lt;P&gt;Oui, c'est ce que je voulais dire.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Je souhaite uniquement traité les calques nommés "0" "1" "2" "3" ... "10"&lt;/P&gt;&lt;P&gt;et non pas les calques nommés "ABC" et "VEC" .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Remerciements,&lt;/P&gt;&lt;P&gt;Armand&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 10:50:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10166790#M17167</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-18T10:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: I want in C#, count the number of layers included in the current file.</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10167014#M17168</link>
      <description>&lt;P&gt;On peut filtrer le calques par nom avec la méthode int.TryParse.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;var layersToProcess = new List&amp;lt;LayerTableRecord&amp;gt;();
foreach (ObjectId id in layerTable)
{
    var layer = (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead);
    if (int.TryParse(layer.Name, out int _))
    {
        layersToProcess.Add(layer);
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;Ou utiliser Linq et Regex&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;var layersToProcess = layerTable
    .Cast&amp;lt;ObjectId&amp;gt;()
    .Select(id =&amp;gt; (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead))
    .Where(l =&amp;gt; Regex.IsMatch(l.Name, @"^\d+$"))
    .ToList();&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 18 Mar 2021 12:14:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10167014#M17168</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-03-18T12:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: I want in C#, count the number of layers included in the current file.</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10167492#M17169</link>
      <description>&lt;P&gt;Merci beaucoup Gilles,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;J'ai réussi à filtré ! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 14:48:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-want-in-c-count-the-number-of-layers-included-in-the-current/m-p/10167492#M17169</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-18T14:48:52Z</dc:date>
    </item>
  </channel>
</rss>

