<?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: Changing the VP Color for a Layer on a drawing database. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12537695#M5666</link>
    <description>&lt;P&gt;Sorry, I was in a hurry and didn't carefully read your description nor the code. I can't really test the code since it uses information from a Form. Here is a very simple test that shows it does get the correct override. I created a layer named TestLayer, in a viewport I changed it's VPOverride to Red. The I set the current space to Paper and ran the following test code. It correctly reports this:&lt;/P&gt;
&lt;P&gt;Command: TESTVPLAYER&lt;/P&gt;
&lt;P&gt;Select Viewport: TestLayer VP Color Override in current VP is red&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;        [CommandMethod("TestVPLayer")]
        public void testvplayer()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var entPrompt = new PromptEntityOptions("\nSelect Viewport");
            entPrompt.SetRejectMessage("...not a Viewport! Try again.");
            entPrompt.AddAllowedClass(typeof(Viewport), true);
            var entSel = ed.GetEntity(entPrompt);
            if (entSel.Status != PromptStatus.OK)
                return;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
                var layer = (LayerTableRecord)tr.GetObject(lt["TestLayer"], OpenMode.ForRead);
                var vp = (Viewport)tr.GetObject(entSel.ObjectId, OpenMode.ForRead);
                var vpOride = layer.GetViewportOverrides(vp.ObjectId);
                ed.WriteMessage("TestLayer VP Color Override in current VP is {0}", vpOride.Color.ColorNameForDisplay);
            }
        }
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Feb 2024 23:25:03 GMT</pubDate>
    <dc:creator>Jeff_M</dc:creator>
    <dc:date>2024-02-02T23:25:03Z</dc:date>
    <item>
      <title>Changing the VP Color for a Layer on a drawing database.</title>
      <link>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12532949#M5661</link>
      <description>&lt;P&gt;I am trying to open a drawing and access a layers VP Color field. I have gotten the Layers that I want to access and change, but the LayerTableRecord only has a Color field, and no VPColor field. I want to keep the Color of a layer as Red but show up in viewports as Cyan.&lt;BR /&gt;&lt;BR /&gt;What can I do to do this?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 22:10:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12532949#M5661</guid>
      <dc:creator>Poncho_Slim</dc:creator>
      <dc:date>2024-01-31T22:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the VP Color for a Layer on a drawing database.</title>
      <link>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12533024#M5662</link>
      <description>&lt;P&gt;Have you looked at the&amp;nbsp;GetViewportOverrides method of the LayerTableRecord? Set the color in the overrides you get from that.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 22:50:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12533024#M5662</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2024-01-31T22:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the VP Color for a Layer on a drawing database.</title>
      <link>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12535244#M5663</link>
      <description>&lt;P&gt;So I started to go down the direction of accessing the VP Color via this method.&lt;BR /&gt;The following code is my massively large approach to trying to change the VP Color for a Viewport on specified Layout.&lt;BR /&gt;&lt;BR /&gt;I first start by gathering the layers that I want to remain Red.&lt;BR /&gt;I then attempt to get the Viewport in a Layout so I can try to change the VP Layer in that viewport for all the layers with a specified string that is not in my list of gathered Layers. I want to change the VP Colors for those layers to Cyan.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran some testing by going into a drawing, creating some DeltaBlocks, and linked them to a cloud. This then created two layers both for the DeltaBlock and the Cloud. I then went into a layout, clicked in the viewport, and changed the VP Layer for the DeltaBlock to Magenta. Going back into ModelSpace and it was still red.&lt;BR /&gt;Then I ran my code, and the Color for that deltablock was red, and the suspected "VP Color" I pulled was still also red. I was expecting for it to be magenta since I believe I have accessed the VP Color via the GetViewportOverrides using the Viewport I have pulled from the Layout. So I was expecting for the second output to be Magenta.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;private void ViewportLayerHandling()
        {
            List&amp;lt;string&amp;gt; LayersToKeep = new List&amp;lt;string&amp;gt;();
            DB_Sheet Sheet;
            LayerTable layerTable;
            ObjectId ViewportID;
            foreach (DataGridViewRow Row in PlanSheetsAvailableTable.Rows)
            {
                LayersToKeep.Clear();
                // Gather the Layers to Keep
                // Go through the Deltas
                for (int i = 0; i &amp;lt; DeltaSheets.Length; i++)
                {
                    Sheet = DeltaSheets[i].Item2;

                    // Get the Deltas only for the RSSheet
                    if (Sheet.sheetNumber == Row.Cells[SheetNumColumnIndex].Value.ToString())
                    {
                        DB_Delta Delta = DeltaSheets[i].Item1;
                        string Handle = Delta.handle;
                        string FilePath = $"{Sheet.fullPath}\\{Sheet.fileName}";
                        Database db = OpenDrawingFile(FilePath); // False = Project is opened in the background
                        ObjectId DeltaBlock = GetBlockIdByHandle(db, Handle);
                        using (Transaction tr = db.TransactionManager.StartTransaction())
                        {
                            // Pull its BlockLayer
                            BlockReference Block = tr.GetObject(DeltaBlock, OpenMode.ForRead) as BlockReference;
                            layerTable = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                            LayerTableRecord BlockLayer = tr.GetObject(Block.LayerId, OpenMode.ForWrite) as LayerTableRecord;
                            Debug.Print($"Block Name:{Block.Name}");
                            Debug.Print($"Block Layer Name:{BlockLayer.Name}");
                            // Add it to the list
                            LayersToKeep.Add(BlockLayer.Name);
                            Debug.Print($"Block Layer:{BlockLayer.Color}");
                            try
                            {
                                // Get the Cloud Layer and also add it to the list
                                ObjectId CloudLayerId = layerTable[$"{BlockLayer.Name}-Cloud"];
                                LayerTableRecord CloudLayer = tr.GetObject(CloudLayerId, OpenMode.ForWrite) as LayerTableRecord;
                                Debug.Print($"Cloud Layer Name:{CloudLayer.Name}");
                                LayersToKeep.Add(CloudLayer.Name);
                            }
                            catch (Autodesk.AutoCAD.Runtime.Exception ex)
                            {
                                Debug.Print($"LayerNotFound:{ex.Message}");
                            }
                        }


                    }
                }
                // Go through the Drawing, and for every Delta that is not in the List
                foreach (string LayerName in LayersToKeep)
                {
                    Debug.Print($"LayerName in List:{LayerName}");
                }

                Debug.Print("-------------------------------------------------");

                // Get the Document
                Sheets.TryGetValue(Row.Cells[SheetNumColumnIndex].Value.ToString(), out Sheet);

                // Get the Deltas only for the RSSheet
                if (Sheet.sheetNumber == Row.Cells[SheetNumColumnIndex].Value.ToString())
                {
                    // Open the drawing
                    string FilePath = $"{Sheet.fullPath}\\{Sheet.fileName}";
                    Database db = OpenDrawingFile(FilePath); // False = Project is opened in the background
                    ViewportID = db.ViewportTableId;
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        // Open the Layout Dictionary
                        DBDictionary LayoutList = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
                        // Go through the Layouts
                        foreach (DBDictionaryEntry layoutId in LayoutList)
                        {
                            // Get the Layout
                            Layout layout = tr.GetObject(layoutId.Value, OpenMode.ForRead) as Layout;
                            // When the Layout is correct
                            if (layout.LayoutName == Row.Cells[SheetNumColumnIndex].Value.ToString())
                            {
                                // Get the Layouts's BlockTableRecord
                                BlockTableRecord LayoutBlockTableRecord = tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead) as BlockTableRecord; 
                                // Go through the Sheet BlockTable
                                foreach (ObjectId ID in LayoutBlockTableRecord)
                                {
                                    // Try to pull the Viewport from the Layout BlockTable
                                    Viewport vp = tr.GetObject(ID, OpenMode.ForRead) as Viewport;
                                    if (vp != null)
                                    {
                                        // This is believed to be a Viewport in a Sepcified Layout
                                        Debug.Print($"vp.BlockName:{vp.BlockName}");
                                        Debug.Print($"vp.BlockId:{vp.BlockId}");
                                        // Save the ID for the suspected Viewport
                                        ViewportID = vp.BlockId;
                                    }
                                }
                            }
                        }

                        // Get the LayerTable
                        layerTable = tr.GetObject(db.LayerTableId, OpenMode.ForRead)as LayerTable;
                        // Go through the layers
                        SymbolTableEnumerator layerEnumerator = layerTable.GetEnumerator();
                        while (layerEnumerator.MoveNext())
                        {
                            // Get the layer
                            LayerTableRecord currentLayer = tr.GetObject(layerEnumerator.Current, OpenMode.ForRead) as LayerTableRecord;
                            // Check the Layer by the Name
                            if (currentLayer.Name.Contains("Delta$-") &amp;amp;&amp;amp; !LayersToKeep.Contains(currentLayer.Name))
                            {
                                // Access the Data on the Layer
                                Debug.Print($"CurrentLayerName:{currentLayer.Name}");
                                Debug.Print($"CurrentLayerColor:{currentLayer.Color}");
                                Debug.Print($"CurrentLayerVPColor:{currentLayer.GetViewportOverrides(ViewportID).Color}");
                                //currentLayer.GetViewportOverrides(ViewportID).Color = Autodesk.AutoCAD.Colors.Color.FromRgb(0,255,255);
                            }
                        }

                    }
                }
            }
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*Moderator edit* Changed code window language to C#.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 21:26:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12535244#M5663</guid>
      <dc:creator>Poncho_Slim</dc:creator>
      <dc:date>2024-02-01T21:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the VP Color for a Layer on a drawing database.</title>
      <link>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12535307#M5664</link>
      <description>&lt;P&gt;Is this the whole code? I'm not seeing that you Commit() the transaction.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 21:53:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12535307#M5664</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2024-02-01T21:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the VP Color for a Layer on a drawing database.</title>
      <link>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12535368#M5665</link>
      <description>&lt;P&gt;this is correct, but I did not really try to make a change. The core of the code is to access the VP Color for the Layer within a Viewport. I would change the color on line 116 and then commit the transaction, but before that, I want to ensure that I am accessing the correct field by outputting the colors and comparing it to what I expected. Since the colors are not what I expected, I am under the impression that I am not in the correct area.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 22:31:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12535368#M5665</guid>
      <dc:creator>Poncho_Slim</dc:creator>
      <dc:date>2024-02-01T22:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the VP Color for a Layer on a drawing database.</title>
      <link>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12537695#M5666</link>
      <description>&lt;P&gt;Sorry, I was in a hurry and didn't carefully read your description nor the code. I can't really test the code since it uses information from a Form. Here is a very simple test that shows it does get the correct override. I created a layer named TestLayer, in a viewport I changed it's VPOverride to Red. The I set the current space to Paper and ran the following test code. It correctly reports this:&lt;/P&gt;
&lt;P&gt;Command: TESTVPLAYER&lt;/P&gt;
&lt;P&gt;Select Viewport: TestLayer VP Color Override in current VP is red&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;        [CommandMethod("TestVPLayer")]
        public void testvplayer()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var entPrompt = new PromptEntityOptions("\nSelect Viewport");
            entPrompt.SetRejectMessage("...not a Viewport! Try again.");
            entPrompt.AddAllowedClass(typeof(Viewport), true);
            var entSel = ed.GetEntity(entPrompt);
            if (entSel.Status != PromptStatus.OK)
                return;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
                var layer = (LayerTableRecord)tr.GetObject(lt["TestLayer"], OpenMode.ForRead);
                var vp = (Viewport)tr.GetObject(entSel.ObjectId, OpenMode.ForRead);
                var vpOride = layer.GetViewportOverrides(vp.ObjectId);
                ed.WriteMessage("TestLayer VP Color Override in current VP is {0}", vpOride.Color.ColorNameForDisplay);
            }
        }
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 23:25:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/changing-the-vp-color-for-a-layer-on-a-drawing-database/m-p/12537695#M5666</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2024-02-02T23:25:03Z</dc:date>
    </item>
  </channel>
</rss>

