<?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: Viewport.CustomScale returns extra scale value of 1 in all layouts in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/viewport-customscale-returns-extra-scale-value-of-1-in-all/m-p/12561497#M5466</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;I retrieved the viewport number but it is still confusing in Layout2. Both viewport numbers are -1 (inactive). I want to filter out the one that has scale 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Gauzdx_0-1707980298984.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1326296i379D270649521AD8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Gauzdx_0-1707980298984.png" alt="Gauzdx_0-1707980298984.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Feb 2024 06:58:28 GMT</pubDate>
    <dc:creator>Gauzdx</dc:creator>
    <dc:date>2024-02-15T06:58:28Z</dc:date>
    <item>
      <title>Viewport.CustomScale returns extra scale value of 1 in all layouts</title>
      <link>https://forums.autodesk.com/t5/net-forum/viewport-customscale-returns-extra-scale-value-of-1-in-all/m-p/12561455#M5464</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to loop through all layouts in the drawing and get viewports' custom scale that are under them. I am able to get the value but confused with the output I am getting. There are two rows in my extract that tells me two scales of the viewport. I created 3 viewports in Layout1 and 1 viewport in Layout2. But I am not sure why there is an extra viewport showing up with scale as 1 in both layout 1 &amp;amp; 2 (see line 3 and 11 in the picture). I am filtering the model space viewport in my code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Gauzdx_0-1707978278383.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1326293iF0755E53E97419E3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Gauzdx_0-1707978278383.png" alt="Gauzdx_0-1707978278383.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;public static void GetLayouts(Transaction tr, Database db, BlockTable bt, string dataOutputPath, string dwgName)
{
	StringBuilder csvLayoutList = new StringBuilder();
	csvLayoutList.AppendLine("HeaderToBeEditedLater");

	//Open the Layout dictionary
	DBDictionary layoutDict = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;

	//Iterate through each layout
	foreach (DBDictionaryEntry layoutentry in layoutDict)
	{
		ObjectId layoutId = layoutentry.Value;
		Layout layout = tr.GetObject(layoutId, OpenMode.ForRead) as Layout;

		if (layout.LayoutName.Equals("Model", StringComparison.OrdinalIgnoreCase))
		{
			continue;
		}
		//csvLayoutList.AppendLine(layout.LayoutName);

		BlockTableRecord layoutbtr = tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead) as BlockTableRecord;
		foreach (ObjectId layoutentId in layoutbtr)
		{
			AcadEntity layent = tr.GetObject(layoutentId, OpenMode.ForRead) as AcadEntity;
			if (layent != null &amp;amp;&amp;amp; layent is Viewport)
			{
				Viewport viewport = layent as Viewport;
				csvLayoutList.AppendLine(layout.LayoutName);
				csvLayoutList.AppendLine($"Viewport Scale: {viewport.CustomScale}");
			}
		}
	}
	File.WriteAllText(dataOutputPath + "\\LayoutList.csv", csvLayoutList.ToString());
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2024 06:29:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/viewport-customscale-returns-extra-scale-value-of-1-in-all/m-p/12561455#M5464</guid>
      <dc:creator>Gauzdx</dc:creator>
      <dc:date>2024-02-15T06:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Viewport.CustomScale returns extra scale value of 1 in all layouts</title>
      <link>https://forums.autodesk.com/t5/net-forum/viewport-customscale-returns-extra-scale-value-of-1-in-all/m-p/12561471#M5465</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;In addition to floating viewports, each layout has its own viewport (which &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_DatabaseServices_Viewport_Number" target="_blank" rel="noopener"&gt;Number&lt;/A&gt; property is always equal to 1).&lt;/P&gt;
&lt;P&gt;Try replacing:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;if (layent != null &amp;amp;&amp;amp; layent is Viewport)
{
    Viewport viewport = layent as Viewport;
    csvLayoutList.AppendLine(layout.LayoutName);
    csvLayoutList.AppendLine($"Viewport Scale: {viewport.CustomScale}");
}&lt;/LI-CODE&gt;
&lt;P&gt;with:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;if (layent != null &amp;amp;&amp;amp; layent is Viewport viewport &amp;amp;&amp;amp; viewport.Number != 1)
{
    csvLayoutList.AppendLine(layout.LayoutName);
    csvLayoutList.AppendLine($"Viewport Scale: {viewport.CustomScale}");
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2024 06:49:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/viewport-customscale-returns-extra-scale-value-of-1-in-all/m-p/12561471#M5465</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-02-15T06:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Viewport.CustomScale returns extra scale value of 1 in all layouts</title>
      <link>https://forums.autodesk.com/t5/net-forum/viewport-customscale-returns-extra-scale-value-of-1-in-all/m-p/12561497#M5466</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;I retrieved the viewport number but it is still confusing in Layout2. Both viewport numbers are -1 (inactive). I want to filter out the one that has scale 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Gauzdx_0-1707980298984.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1326296i379D270649521AD8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Gauzdx_0-1707980298984.png" alt="Gauzdx_0-1707980298984.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2024 06:58:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/viewport-customscale-returns-extra-scale-value-of-1-in-all/m-p/12561497#M5466</guid>
      <dc:creator>Gauzdx</dc:creator>
      <dc:date>2024-02-15T06:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Viewport.CustomScale returns extra scale value of 1 in all layouts</title>
      <link>https://forums.autodesk.com/t5/net-forum/viewport-customscale-returns-extra-scale-value-of-1-in-all/m-p/12561553#M5467</link>
      <description>&lt;P&gt;This is because the layout have never been active before.&lt;/P&gt;
&lt;P&gt;You can use the LayoutManager to activate each layout before processing it. To be able to use the Layoutmanager, the processed Database have to be the working database. So, if you call this method on a 'side database' you have to set it as working database. This can be done using the &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;'s &lt;A href="https://forums.autodesk.com/t5/net/want-to-have-c-program-to-modify-dwg-and-save-into-dwg-format/m-p/12439905/highlight/true#M79788" target="_blank" rel="noopener"&gt;WorkingDatabase&lt;/A&gt; class.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        public static string GetLayouts(Transaction tr, Database db)
        {
            var layoutManager = LayoutManager.Current;
            string currentLayout = layoutManager.CurrentLayout;
            var stringBuilder = new StringBuilder();
            var layoutDictionary = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
            foreach (DBDictionaryEntry entry in layoutDictionary)
            {
                if (entry.Value == SymbolUtilityServices.GetBlockModelSpaceId(db))
                    continue;
                var layout = (Layout)tr.GetObject(entry.Value, OpenMode.ForRead);
                layoutManager.CurrentLayout = layout.LayoutName;
                var layoutBtr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead);
                foreach (ObjectId id in layoutBtr)
                {
                    if (id.ObjectClass.Name == "AcDbViewport")
                    {
                        var viewport = (Viewport)tr.GetObject(id, OpenMode.ForRead);
                        if (viewport.Number != 1)
                        {
                            stringBuilder.AppendLine(layout.LayoutName);
                            stringBuilder.AppendLine($"Viewport Scale: {viewport.CustomScale}");
                        }
                    }
                }
            }
            layoutManager.CurrentLayout = currentLayout;
            return stringBuilder.ToString();
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 15 Feb 2024 07:33:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/viewport-customscale-returns-extra-scale-value-of-1-in-all/m-p/12561553#M5467</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-02-15T07:33:08Z</dc:date>
    </item>
  </channel>
</rss>

