<?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: Keep x-ref layer settings in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/11682250#M10492</link>
    <description>&lt;P&gt;Okay, maybe now holidays is over I hope some-one knows how to solve it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like I said, problem is, when copying a drawing together with its xrefs to a new folder, the layersettings in the new drawing are lost. For example, in the original x-ref the color of a layer is blue &amp;amp; in the drawing containing the x-ref its set to yellow, then in the copied version the color of the layer is blue in the x-ref AND in the drawing containing the x-ref). This as well goes for viewport-overrides (off-course). Somehow this information is lost purely by changing the x-ref path. While, when doing this by hand, it doesn't happen.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Because there's drawings with lots of viewports and lots of x-refs, PLUS you can't really identify a viewport, I neither see a way to set all the settings again, because they might differ between different viewports in the same layer.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Jan 2023 12:28:14 GMT</pubDate>
    <dc:creator>stefanveurink68AXD</dc:creator>
    <dc:date>2023-01-16T12:28:14Z</dc:date>
    <item>
      <title>Keep x-ref layer settings</title>
      <link>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/11648406#M10489</link>
      <description>&lt;P&gt;So I've got some code to copy a drawing including references files. This means in the copy, the path to the reference-files have to be set to the copies of the references.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Autocad you can then simply can change the 'saved path' field in the reference manager.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tried to do this in C# with:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Database dat = new Database(false, true);

                using (dat)
                {
                    dat.ReadDwgFile(tek.padNIEUW, System.IO.FileShare.ReadWrite, true, "");

                    using (Transaction tr = dat.TransactionManager.StartTransaction())
                    {
                        XrefGraph xg = dat.GetHostDwgXrefGraph(true);
                        int count = xg.NumNodes;
                        if (count &amp;gt; 1) //anders loopt die vast als er 0 xrefs zijn in een tek. 
                        {
                            for (int i = 1; i &amp;lt; count; i++)
                            {
                                XrefGraphNode xrNode = xg.GetXrefNode(i);
                                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(xrNode.BlockTableRecordId, OpenMode.ForWrite);
                                dat.XrefEditEnabled = true;
                                string naam = btr.Name;
                                if (btr.IsResolved == false)
                                {
                                    string nieuwpad = "";
                                    foreach (Xref xr in gebruikteXrefs)
                                    {
                                        if (xr.naam == naam)
                                        {
                                            nieuwpad = xr.vollepadNIEUW;
                                        }
                                    }
                                    btr.PathName = nieuwpad;
                                }
                            }
                            tr.Commit();
                        }
                    }
                    dat.SaveAs(tek.padNIEUW, DwgVersion.Current);
                }
            &lt;/LI-CODE&gt;&lt;P&gt;however this isn't working correctly. it does set the new path to the new x-ref yes, but all the layersettings and stuff are forgotten. so for example, when in the drawing setting layercolor of an x-ref-layer to blue (while in the x-ref itself it is yellow), after changing the x-ref-path the setting is forgotten, so in the drawing i see an yellow layer instead of a blue. This doesn't happen when you change the path in autocad itself (so without .net).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is going wrong here? And more important how to solve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Dec 2022 13:07:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/11648406#M10489</guid>
      <dc:creator>stefanveurink68AXD</dc:creator>
      <dc:date>2022-12-30T13:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Keep x-ref layer settings</title>
      <link>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/11649126#M10490</link>
      <description>&lt;P&gt;is there something wrong with&amp;nbsp; my questions? why do none of them get answered lately?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Dec 2022 20:56:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/11649126#M10490</guid>
      <dc:creator>stefanveurink68AXD</dc:creator>
      <dc:date>2022-12-30T20:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Keep x-ref layer settings</title>
      <link>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/11651048#M10491</link>
      <description>&lt;P&gt;Probably because everyone's on vacation due to the holidays.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jan 2023 17:20:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/11651048#M10491</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2023-01-01T17:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Keep x-ref layer settings</title>
      <link>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/11682250#M10492</link>
      <description>&lt;P&gt;Okay, maybe now holidays is over I hope some-one knows how to solve it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like I said, problem is, when copying a drawing together with its xrefs to a new folder, the layersettings in the new drawing are lost. For example, in the original x-ref the color of a layer is blue &amp;amp; in the drawing containing the x-ref its set to yellow, then in the copied version the color of the layer is blue in the x-ref AND in the drawing containing the x-ref). This as well goes for viewport-overrides (off-course). Somehow this information is lost purely by changing the x-ref path. While, when doing this by hand, it doesn't happen.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Because there's drawings with lots of viewports and lots of x-refs, PLUS you can't really identify a viewport, I neither see a way to set all the settings again, because they might differ between different viewports in the same layer.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 12:28:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/11682250#M10492</guid>
      <dc:creator>stefanveurink68AXD</dc:creator>
      <dc:date>2023-01-16T12:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Keep x-ref layer settings</title>
      <link>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/11983479#M10493</link>
      <description>&lt;P&gt;nobody got an answer to this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Isn't there a way to recognize the viewports in both drawings, so you can find which one are the same, and attach te layersettings again in the copied drawing? Guess the same viewport in original and new drawing got a different object-id or does this stay the same?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 17:33:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/11983479#M10493</guid>
      <dc:creator>stefanveurink68AXD</dc:creator>
      <dc:date>2023-05-23T17:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Keep x-ref layer settings</title>
      <link>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/12042950#M10494</link>
      <description>&lt;P&gt;what is XREFOVERRIDE &amp;amp; VISRETAIN set to in original and new drawing?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2023 02:48:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/12042950#M10494</guid>
      <dc:creator>jeffHGCE</dc:creator>
      <dc:date>2023-06-19T02:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: Keep x-ref layer settings</title>
      <link>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/12725733#M10495</link>
      <description>&lt;P&gt;Maybe a little late, but no, this is not the solution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, now I'm trying to copy all the settings from the old drawing to the new one, however, it gives me an eWrongDatabase at ltrv.linetypeobjectid = lov.vpproperties.linetypeobjectid.&amp;nbsp;&lt;/P&gt;&lt;P&gt;which makes sense cause it's the objectid from the original drawing, however I suspect, if I copy the drawing, this would make the objectid the same?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So simple solution would be to just ignore it, however, then the code doesn't continue, so is there an other way to ignore this problem?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some code (it's not easy to share all of it):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;                    using (Transaction tr = dat.TransactionManager.StartTransaction())
                    {
                        var layoutDict = (DBDictionary)tr.GetObject(dat.LayoutDictionaryId, OpenMode.ForRead);
                        int nr = 0;
                        LayerTable tabel = (LayerTable)tr.GetObject(dat.LayerTableId, OpenMode.ForWrite);

                        foreach (DBDictionaryEntry entry in layoutDict)
                        {
                            if (entry.Key != "Model")
                            {
                                var layout = (Layout)tr.GetObject(entry.Value, OpenMode.ForWrite);
                                foreach (ObjectId vpId in layout.GetViewports())
                                {
                                    nr++;

                                    var viewport = (Autodesk.AutoCAD.DatabaseServices.Viewport)tr.GetObject(vpId, OpenMode.ForWrite);

                                    foreach (vp viewp in tek.viewports)
                                    {
                                        if (nr == viewp.nr)
                                        {
                                            viewport.ThawAllLayersInViewport();



                                            ObjectIdCollection tefreezenlayers = new ObjectIdCollection();

                                            foreach (ObjectId layerid in tabel)
                                            {
                                                LayerTableRecord ltr = tr.GetObject(layerid, OpenMode.ForWrite) as LayerTableRecord;
                                                string naam = ltr.Name;
                                                LayerViewportProperties  ltrv = ltr.GetViewportOverrides(vpId);
                                                

                                                foreach (laagmetoverrides lov in viewp.overrides)
                                                {
                                                    if (lov.laagnaam == naam)
                                                    {
                                                        ltrv.Color = lov.vpproperties.Color;
                                                        ltrv.LinetypeObjectId = lov.vpproperties.LinetypeObjectId; 
                                                        ltrv.LineWeight = lov.vpproperties.LineWeight;
                                                        ltrv.PlotStyleName = lov.vpproperties.PlotStyleName;
                                                        ltrv.PlotStyleNameId = lov.vpproperties.PlotStyleNameId;
                                                        ltrv.Transparency = lov.vpproperties.Transparency;
                                                        tefreezenlayers.Add(layerid);
                                                    }        
                                                }
                                            }
                                           viewport.FreezeLayersInViewport(tefreezenlayers.GetEnumerator()); 
                                        }
                                    }
                                }
                            }
                        }
                        tr.Commit();
                    }&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 22 Apr 2024 19:38:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/keep-x-ref-layer-settings/m-p/12725733#M10495</guid>
      <dc:creator>stefanveurink68AXD</dc:creator>
      <dc:date>2024-04-22T19:38:15Z</dc:date>
    </item>
  </channel>
</rss>

