<?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: checking if an enitities layer is off in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10970565#M13520</link>
    <description>&lt;P&gt;Hello sir&lt;/P&gt;&lt;P&gt;what I want to do is to check if an entity is in a layer which is set to off, I want to leave it as it is, otherwise, I want to set its layer to lets say "0".&lt;/P&gt;&lt;P&gt;the first thing I did was get the layer table record, and:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;string hiddenlayers;&lt;/P&gt;&lt;P&gt;if(layer.isoff)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;trans.getobject(layertabID , openmode.forwrite);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;hiddenlayers +=layer.name + ","&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;blocktalbe bt = tr.getobject(db.BlockTable, openmode.forread) as BlockTable;&lt;/P&gt;&lt;P&gt;foreach (objectID btid in bt)&lt;/P&gt;&lt;P&gt;{&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;BlockTableRecord btr = tr.GetObject(btid, openmode.forread) as BlockTableRecord;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;foreach( ObjectID id in btr)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;entity ent= tr.GetObject(id, openmode.forwrite) as entity;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;if(hiddenlayers.contains(entity.layer + ",") continue;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;entity.layer="0";&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;entity.color=256;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;but when i run the program, even entities in layers which are set to off, are set to layer "0" and are visible.&lt;/P&gt;&lt;P&gt;I cant figure out how to fix it.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Feb 2022 19:34:24 GMT</pubDate>
    <dc:creator>a.kouchakzadeh</dc:creator>
    <dc:date>2022-02-24T19:34:24Z</dc:date>
    <item>
      <title>checking if an enitities layer is off</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10970257#M13518</link>
      <description>&lt;P&gt;hi every one&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I searched the net to find out how is it possible to check if an entities layer is set to off, but I couldn't come up with anything. can anyone give me a hand on this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i extracted the entity using the transaction&lt;/P&gt;&lt;P&gt;I can set the entity.layer="..."&lt;/P&gt;&lt;P&gt;but i dont know how to check if its layer is off.&lt;/P&gt;&lt;P&gt;entity.layer.isoff doesn't work&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 16:47:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10970257#M13518</guid>
      <dc:creator>a.kouchakzadeh</dc:creator>
      <dc:date>2022-02-24T16:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: checking if an enitities layer is off</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10970424#M13519</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You do not need to check all the entities, you have to directly check each LayerTableRecord. This is done iterating through the layer table.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 18:21:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10970424#M13519</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-02-24T18:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: checking if an enitities layer is off</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10970565#M13520</link>
      <description>&lt;P&gt;Hello sir&lt;/P&gt;&lt;P&gt;what I want to do is to check if an entity is in a layer which is set to off, I want to leave it as it is, otherwise, I want to set its layer to lets say "0".&lt;/P&gt;&lt;P&gt;the first thing I did was get the layer table record, and:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;string hiddenlayers;&lt;/P&gt;&lt;P&gt;if(layer.isoff)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;trans.getobject(layertabID , openmode.forwrite);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;hiddenlayers +=layer.name + ","&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;blocktalbe bt = tr.getobject(db.BlockTable, openmode.forread) as BlockTable;&lt;/P&gt;&lt;P&gt;foreach (objectID btid in bt)&lt;/P&gt;&lt;P&gt;{&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;BlockTableRecord btr = tr.GetObject(btid, openmode.forread) as BlockTableRecord;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;foreach( ObjectID id in btr)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;entity ent= tr.GetObject(id, openmode.forwrite) as entity;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;if(hiddenlayers.contains(entity.layer + ",") continue;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;entity.layer="0";&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;entity.color=256;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;but when i run the program, even entities in layers which are set to off, are set to layer "0" and are visible.&lt;/P&gt;&lt;P&gt;I cant figure out how to fix it.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 19:34:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10970565#M13520</guid>
      <dc:creator>a.kouchakzadeh</dc:creator>
      <dc:date>2022-02-24T19:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: checking if an enitities layer is off</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10970896#M13521</link>
      <description>&lt;P&gt;Rather than using a string to store the name of off layers, you should use a &lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1?view=netframework-4.5" target="_blank" rel="noopener"&gt;List&amp;lt;string&amp;gt;&lt;/A&gt; or, more efficient with Contains, a &lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1?view=netframework-4.5" target="_blank" rel="noopener"&gt;HashSet&amp;lt;string&amp;gt;&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;    using (var tr = db.TransactionManager.StartTransaction())
    {
        // collect all off layer names
        var layerTable = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
        var offLayers = new HashSet&amp;lt;string&amp;gt;();
        foreach (ObjectId id in layerTable)
        {
            var layer = (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead);
            if (layer.IsOff)
                offLayers.Add(layer.Name);
        }
        // get all entities
        var blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
        foreach (ObjectId btrId in blockTable)
        {
            var btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);
            foreach (ObjectId id in btr)
            {
                var entity = (Entity)tr.GetObject(id, OpenMode.ForRead);
                if (offLayers.Contains(entity.Layer))
                    continue;
                entity.Layer = "0";
                entity.ColorIndex = 256;
            }
        }
        tr.Commit();
    }&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 24 Feb 2022 23:31:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10970896#M13521</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-02-24T23:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: checking if an enitities layer is off</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10971568#M13522</link>
      <description>&lt;P&gt;I have done exactly as you said, but it sill doesnt work properly.&lt;/P&gt;&lt;P&gt;for example, in this drawing file, fancoildet layer is set to off. after you run the program, it sets that layer to what ever you have chosen as well.&lt;/P&gt;&lt;P&gt;any idea why this happens?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Feb 2022 10:40:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10971568#M13522</guid>
      <dc:creator>a.kouchakzadeh</dc:creator>
      <dc:date>2022-02-25T10:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: checking if an enitities layer is off</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10971605#M13523</link>
      <description>&lt;P&gt;I do not understand what you mean with " it sill doesnt work properly."&lt;/P&gt;
&lt;P&gt;From the test I did the layer and color of entities is changed if the layer of the entity is On and remain the same if the layer is Off.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10854705"&gt;@a.kouchakzadeh&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;for example, in this drawing file, fancoildet layer is set to off. after you run the program, it sets that layer to what ever you have chosen as well.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It doesn't seems to be the case for me.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_gile_0-1645786878999.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1029689iCA78738A9CE0726B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="_gile_0-1645786878999.png" alt="_gile_0-1645786878999.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Feb 2022 11:01:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10971605#M13523</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-02-25T11:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: checking if an enitities layer is off</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10972259#M13524</link>
      <description>&lt;P&gt;I assume Im not explaining my problem correctly.&lt;/P&gt;&lt;P&gt;in this picture, which is the original drawing before I run the program, you can see there are elements which are in layers that are set to off. you can see where they are, but they are hidden:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="before.JPG" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1029857i5B99220FD3876C2C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="before.JPG" alt="before.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;after I run the program, the elements that were in off layers are suppose to stay on off layers.&lt;/P&gt;&lt;P&gt;but this is not the case because they appear and that means their layer has changed to the one that the user has selected:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="after.JPG" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1029855iDCAC8703C072BE94/image-size/medium?v=v2&amp;amp;px=400" role="button" title="after.JPG" alt="after.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Feb 2022 16:35:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10972259#M13524</guid>
      <dc:creator>a.kouchakzadeh</dc:creator>
      <dc:date>2022-02-25T16:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: checking if an enitities layer is off</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10972575#M13525</link>
      <description>&lt;P&gt;What you describe is not due to the code I provided.&lt;/P&gt;
&lt;P&gt;The entites you're talking about are on a frozen layer (not off).&lt;/P&gt;</description>
      <pubDate>Fri, 25 Feb 2022 19:28:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10972575#M13525</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-02-25T19:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: checking if an enitities layer is off</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10973282#M13526</link>
      <description>&lt;P&gt;my bad&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":zipper_mouth_face:"&gt;🤐&lt;/span&gt;&lt;/P&gt;&lt;P&gt;thank you sir&lt;/P&gt;</description>
      <pubDate>Sat, 26 Feb 2022 11:46:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-an-enitities-layer-is-off/m-p/10973282#M13526</guid>
      <dc:creator>a.kouchakzadeh</dc:creator>
      <dc:date>2022-02-26T11:46:54Z</dc:date>
    </item>
  </channel>
</rss>

