<?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 thaw one layer in one viewport? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8883520#M21941</link>
    <description>&lt;P&gt;To clarify, I cannot thaw a specific layer for which I already have the name and ID inside of a viewport unless I create a objectId collection for that viewport and step through the collection to find the enumerator for the layer?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jul 2019 18:00:57 GMT</pubDate>
    <dc:creator>sonny3g</dc:creator>
    <dc:date>2019-07-01T18:00:57Z</dc:date>
    <item>
      <title>How to thaw one layer in one viewport?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8883233#M21939</link>
      <description>&lt;P&gt;I have been trying to figure out how to make sure a specific layer is thawed in the current viewport.&amp;nbsp; My program makes sure a layer is thawed when in the model tab.&amp;nbsp; But, I cannot seem to get it to work when in a viewport.&amp;nbsp; I did figure out how to test if my layer is frozen in the viewport but cannot seem to get the layer thawed.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal is to take a given layer and create a sibling layer if the sibling layer does not exist.&amp;nbsp; My code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; //***************************************************************************************************************************
        /// &amp;lt;summary&amp;gt;
        /// Takes selected block layer and creates required sibling layer if it does
        /// not exist and makes it the current layer.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="blkLyrName"&amp;gt;&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
        public string MakeSiblingLayer(string blkLyrName)
        {
            // Intialize the sibling layer namve variable.
            string sibLyrName;
            try
            {
                // Creates new layer name string for sibling layer.
                if (blkLyrName.EndsWith("_CONV"))
                {
                    int cnt = blkLyrName.Length - 5;
                    sibLyrName = blkLyrName.Remove(cnt, 5) + "_DIM_EL";
                }
                else
                {
                    sibLyrName = blkLyrName + "_DIM_EL";
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception a6)
            {
                System.Windows.Forms.MessageBox.Show("ERROR:\n" + a6.ToString());
                return null;
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("ERROR:\n PROGRAM WILL EXIT!");
                return null;
            }
            // Checks for the existence of the sibling layer and creates the new sibling layer if it does not exist.
            using (Transaction mklyrTrans = db.TransactionManager.StartTransaction())
            {
                LayerTable sibLyrTable = mklyrTrans.GetObject(db.LayerTableId, OpenMode.ForWrite) as LayerTable;
                LayerTableRecord sibLTRec = mklyrTrans.GetObject(db.Clayer, OpenMode.ForWrite) as LayerTableRecord;
                try
                {
                    // Thaws the existing sibling layer if it is frozen and it already exists.
                    if (sibLyrTable.Has(sibLyrName) == true)
                    {
                        using (Transaction frznTrans = db.TransactionManager.StartTransaction())
                        {
                            try
                            {
                                LayerTableRecord frznRec;
                                frznRec = frznTrans.GetObject(sibLyrTable[sibLyrName], OpenMode.ForRead) as LayerTableRecord;
                                if (db.TileMode)
                                {
                                    if (frznRec.IsFrozen == true)
                                    {
                                        frznRec.UpgradeOpen();
                                        frznRec.IsFrozen = false;
                                        frznTrans.Commit();
                                    }
                                    else
                                    {
                                        frznTrans.Dispose();
                                    }
                                }
                                else
                                {
                                    Viewport vp = (Viewport)ed.ActiveViewportId.GetObject(OpenMode.ForRead);

                                    if (vp.IsLayerFrozenInViewport(frznRec.Id))
                                    {
                                       frznRec.UpgradeOpen();
                                       vp.;
                                    }
                                }
                            }
                            catch (Autodesk.AutoCAD.Runtime.Exception fl)
                            {
                                System.Windows.Forms.MessageBox.Show("FROZEN LAYER ERROR:\n" + fl.ToString());
                                return null;
                            }
                            catch
                            {
                                System.Windows.Forms.MessageBox.Show("ERROR:\n PROGRAM WILL EXIT!");
                                return null;
                            }
                        }
                        db.Clayer = sibLyrTable[sibLyrName];
                    }// end if sibLyrTable exists make it current layer
                     // Creates the sibling layer if it does not exist already.
                    else
                    {
                        sibLTRec = mklyrTrans.GetObject(sibLyrTable[blkLyrName], OpenMode.ForWrite).Clone() as LayerTableRecord;
                        sibLTRec.Name = sibLyrName;
                        sibLTRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 7);
                        sibLyrTable.Add(sibLTRec);
                        mklyrTrans.AddNewlyCreatedDBObject(sibLTRec, true);
                        db.Clayer = sibLyrTable[sibLyrName];
                    }// end clone layer if sibling layer does not exist and make new sibling layer the current layer
                }
                catch (Autodesk.AutoCAD.Runtime.Exception a7)
                {
                    System.Windows.Forms.MessageBox.Show("ERROR:\n" + a7.ToString());
                    return null;
                }
                catch
                {
                    System.Windows.Forms.MessageBox.Show("ERROR:\n PROGRAM WILL EXIT!");
                    return null;
                }
                // Commits the transaction to add the sibling layer.
                mklyrTrans.Commit();
            }// end the mklyrTrans transaction
            // Returns the new sibling layer name to the calling program.
            return sibLyrName;
        }
        //***************************************************************************************************************************&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Jul 2019 15:46:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8883233#M21939</guid>
      <dc:creator>sonny3g</dc:creator>
      <dc:date>2019-07-01T15:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to thaw one layer in one viewport?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8883314#M21940</link>
      <description>&lt;P&gt;You should be able to get some inspiration from this snippet (assuming layers is an IEnumerable of string containing the layer names to freeze in the viewport)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;                using (Transaction tr = db.TransactionManager.StartTransaction())
                {&lt;BR /&gt;                    // open the viewport for write
                    Viewport vp = (Viewport)tr.GetObject(vpId, OpenMode.ForWrite);&lt;BR /&gt;&lt;BR /&gt;                    // get the viewport layer
                    LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
                    LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(lt[vp.Layer], OpenMode.ForRead);&lt;BR /&gt;&lt;BR /&gt;                    // unlock the viewport layer if needed
                    bool locked = ltr.IsLocked;
                    if (locked)
                    {
                        ltr.UpgradeOpen();
                        ltr.IsLocked = false;
                    }&lt;BR /&gt;&lt;BR /&gt;                    // freeze the layers in the viewport
                    ObjectIdCollection ids = new ObjectIdCollection();
                    foreach (string layer in layers)
                    {
                        if (lt.Has(layer))
                        {
                            ids.Add(lt[layer]);
                        }
                    }
                    vp.FreezeLayersInViewport(ids.GetEnumerator());&lt;BR /&gt;&lt;BR /&gt;                    // reset the lock state of the viewport layer
                    if (locked)
                        ltr.IsLocked = true;
                    tr.Commit();
                }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 16:16:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8883314#M21940</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-07-01T16:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to thaw one layer in one viewport?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8883520#M21941</link>
      <description>&lt;P&gt;To clarify, I cannot thaw a specific layer for which I already have the name and ID inside of a viewport unless I create a objectId collection for that viewport and step through the collection to find the enumerator for the layer?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 18:00:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8883520#M21941</guid>
      <dc:creator>sonny3g</dc:creator>
      <dc:date>2019-07-01T18:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to thaw one layer in one viewport?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8883694#M21942</link>
      <description>&lt;P&gt;This is the way the &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=OREFNET-Autodesk_AutoCAD_DatabaseServices_Viewport_FreezeLayersInViewport_IEnumerator" target="_blank" rel="noopener"&gt;Viewport.FreezeLayersInViewport()&lt;/A&gt; method works.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 19:17:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8883694#M21942</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-07-01T19:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to thaw one layer in one viewport?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8886979#M21943</link>
      <description>&lt;P&gt;You can build some extension methods to freeze or thaw a single in a viewport by passing a layer name or ObjectId&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    public static class Extension
    {
        public static void FreezeLayer(this Viewport vp, string layerName)
        {
            var layerTable = (LayerTable)vp.Database.LayerTableId.GetObject(OpenMode.ForRead);
            vp.FreezeLayer(layerTable[layerName]);
        }

        public static void FreezeLayer(this Viewport vp, ObjectId layerId)
        {
            if (!layerId.IsNull)
            {
                var ids = new ObjectIdCollection();
                ids.Add(layerId);
                vp.FreezeLayersInViewport(ids.GetEnumerator());
            }
        }

        public static void ThawLayer(this Viewport vp, string layerName)
        {
            var layerTable = (LayerTable)vp.Database.LayerTableId.GetObject(OpenMode.ForRead);
            vp.ThawLayer(layerTable[layerName]);
        }

        public static void ThawLayer(this Viewport vp, ObjectId layerId)
        {
            if (!layerId.IsNull)
            {
                var ids = new ObjectIdCollection();
                ids.Add(layerId);
                vp.ThawLayersInViewport(ids.GetEnumerator());
            }
        }
    }&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jul 2019 06:23:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8886979#M21943</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-07-03T06:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to thaw one layer in one viewport?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8898182#M21944</link>
      <description>&lt;P&gt;Thank you Giles.&amp;nbsp; That was exactly what I needed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My list of subjects to study and learn is getting longer the more I try to write code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am grateful for forums with people who are willing to share their knowledge with the rest of us.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sonny&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 12:10:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-thaw-one-layer-in-one-viewport/m-p/8898182#M21944</guid>
      <dc:creator>sonny3g</dc:creator>
      <dc:date>2019-07-09T12:10:34Z</dc:date>
    </item>
  </channel>
</rss>

