<?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 Ynt: Layout Create in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13761610#M85589</link>
    <description>&lt;P&gt;Still not clear...&lt;/P&gt;
&lt;P&gt;Anyway, as&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;said, to set the view (zoom) in the newly created viewport, you have to convert the coordinates got from the user in model space UCS to WCS and then, from WCS to the viewport DCS.&lt;/P&gt;
&lt;P&gt;Here's a example adapted from your code which uses an extension method from the &lt;A href="https://github.com/gileCAD/GeometryExtensions" target="_blank" rel="noopener"&gt;GeometryExtensions library&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

using System;

[assembly: CommandClass(typeof(CreateLayoutAndViewportSample.Commands))]

namespace CreateLayoutAndViewportSample
{
    public class Commands
    {
        [CommandMethod("TEST", CommandFlags.NoPaperSpace)]
        public static void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            // Prompt the user to get points
            var promptPointResult = ed.GetPoint("\nFirst corner: ");
            if (promptPointResult.Status != PromptStatus.OK)
                return;
            var ucsPt1 = promptPointResult.Value;

            promptPointResult = ed.GetCorner("\nOpposite corner: ", ucsPt1);
            if (promptPointResult.Status != PromptStatus.OK)
                return;
            var ucsPt2 = promptPointResult.Value;

            // Prompt the user for the Layout name
            var promptResult = ed.GetString("\nLayout name");
            if (promptResult.Status != PromptStatus.OK)
                return;
            string layoutName = promptResult.StringResult;

            var layoutManager = LayoutManager.Current;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                // Delete the layout if it already exists
                var layoutDict = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                if (layoutDict.Contains(layoutName))
                    layoutManager.DeleteLayout(layoutName);

                // Create a new Layout
                var layoutId = layoutManager.CreateLayout(layoutName);
                layoutManager.CurrentLayout = layoutName;

                // Create a Viewport
                var vp = new Viewport();
                vp.SetDatabaseDefaults();
                var wcsPt1 = ucsPt1.TransformBy(ed.CurrentUserCoordinateSystem);
                var wcsPt2 = ucsPt2.TransformBy(ed.CurrentUserCoordinateSystem);
                vp.CenterPoint = new LineSegment3d(wcsPt1, wcsPt2).MidPoint;
                vp.Width = Math.Abs(wcsPt1.X - wcsPt2.X);
                vp.Height = Math.Abs(wcsPt1.Y - wcsPt2.Y);

                var layout = (Layout)tr.GetObject(layoutId, OpenMode.ForRead);
                var btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);
                btr.AppendEntity(vp);
                tr.AddNewlyCreatedDBObject(vp, true);

                // Set the viewport view
                vp.On = true;
                var dcsPt1 = wcsPt1.TransformBy(vp.WCS2DCS());
                var dcsPt2 = wcsPt2.TransformBy(vp.WCS2DCS());
                vp.ViewCenter = new Point2d((dcsPt1.X + dcsPt2.X) * 0.5, (dcsPt1.Y + dcsPt2.Y) * 0.5);
                vp.ViewHeight = Math.Abs(dcsPt1.Y - dcsPt2.Y);
                tr.Commit();
            }
        }
    }
    // Extract from https://github.com/gileCAD/GeometryExtensions
    public static class Extension
    {
        /// &amp;lt;summary&amp;gt;
        /// Gets the transformation matrix of the world coordinate system (WCS)
        /// to the display coordinate system (DCS) of the specified window.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="viewport"&amp;gt;The instance to which this method applies.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;The transformation matrix from WCS to DCS.&amp;lt;/returns&amp;gt;
        /// &amp;lt;exception cref="System.ArgumentNullException"&amp;gt;ArgumentException is thrown if &amp;lt;paramref name="viewport"/&amp;gt; is null.&amp;lt;/exception&amp;gt;
        public static Matrix3d WCS2DCS(this Viewport viewport)
        {
            if (viewport is null)
                throw new System.ArgumentNullException(nameof(viewport));
            return
                Matrix3d.WorldToPlane(viewport.ViewDirection) *
                Matrix3d.Displacement(viewport.ViewTarget.GetAsVector().Negate()) *
                Matrix3d.Rotation(viewport.TwistAngle, viewport.ViewDirection, viewport.ViewTarget);
        }
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 10 Aug 2025 16:41:13 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2025-08-10T16:41:13Z</dc:date>
    <item>
      <title>Layout Create</title>
      <link>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13761477#M85586</link>
      <description>&lt;P&gt;Hello friends,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;With this code, I create layout. But there is a problem ...&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Viewport Size Not at P2 points with P1 ..! How can I fix this?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I want; The formation of a single layout-viewport by point P1 and P2. . P1 and P2 in size.&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; [CommandMethod("LCT")]
 public void LayoutCreate()
 {
     var (_, db, ed) = GetActiveDocumentComponents();

     var p1 = ed.GetPoint("\nP1 noktası: ").Value;
     var p2 = ed.GetPoint("\nP2 noktası: ").Value;

     ed.Command("_.ZOOM", "_W", p1, p2);

     var name = ed.GetString("\nLayout ismi: ").StringResult;

     using (var tr = db.TransactionManager.StartTransaction())
     {
         var lm = LayoutManager.Current;
         lm.CreateLayout(name);
         lm.CurrentLayout = name;

         var layoutDict = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
         var layout = (Layout)tr.GetObject((ObjectId)layoutDict[name], OpenMode.ForWrite);
         var btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);

         var toErase = new List&amp;lt;ObjectId&amp;gt;();
         foreach (ObjectId id in btr)
         {
             if (tr.GetObject(id, OpenMode.ForRead) is Autodesk.AutoCAD.DatabaseServices.Viewport)
                 toErase.Add(id);
         }
         foreach (var id in toErase)
         {
             var vpOld = (Autodesk.AutoCAD.DatabaseServices.Viewport)tr.GetObject(id, OpenMode.ForWrite);
             vpOld.Erase();
         }

         var vp = new Autodesk.AutoCAD.DatabaseServices.Viewport();
         vp.SetDatabaseDefaults();
         btr.AppendEntity(vp);
         tr.AddNewlyCreatedDBObject(vp, true);

         vp.On = true;
         vp.ViewCenter = new Point2d((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2);
         vp.ViewHeight = Math.Abs(p2.Y - p1.Y);
         vp.Width = Math.Abs(p2.X - p1.X);
         vp.Height = Math.Abs(p2.Y - p1.Y);
         vp.CenterPoint = new Point3d(vp.Width / 2, vp.Height / 2, 0);
         tr.Commit();
     }
 }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Aug 2025 11:04:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13761477#M85586</guid>
      <dc:creator>k005</dc:creator>
      <dc:date>2025-08-10T11:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: Layout Create</title>
      <link>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13761504#M85587</link>
      <description>&lt;P&gt;It is not very clear what your question is about.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. You created a Layout without explicitly configuring its PlotSettings, so it is not clear if the Viewport not being positioned within the paper size is your issue?&lt;/P&gt;
&lt;P&gt;2. Are the 2 points picked is the REAL points you want on the new layout? If they are, then you may have to configure the layout's PlotSettings to a proper paper size to cover the 2 points.&lt;/P&gt;
&lt;P&gt;3. Since you ask user to select the 2 points before the layout is created, so, the 2 points' value is based on the current space (possibly, ModelSpace), so you may have to transform them properly according to the new layout. One way to save from the point transformation is to create the new layout first and set it as current, then ask user to select points (thus the points are selected on the new layout, then create the viewport.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Aug 2025 12:22:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13761504#M85587</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2025-08-10T12:22:42Z</dc:date>
    </item>
    <item>
      <title>Ynt: Layout Create</title>
      <link>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13761557#M85588</link>
      <description>&lt;P&gt;I add a picture ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2.&amp;nbsp;The picture shows the desired situation. ( After )&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="2025-08-10_170151.jpg" style="width: 651px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1559980i80C13FDCF60E1ADB/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025-08-10_170151.jpg" alt="2025-08-10_170151.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Aug 2025 14:07:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13761557#M85588</guid>
      <dc:creator>k005</dc:creator>
      <dc:date>2025-08-10T14:07:19Z</dc:date>
    </item>
    <item>
      <title>Ynt: Layout Create</title>
      <link>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13761610#M85589</link>
      <description>&lt;P&gt;Still not clear...&lt;/P&gt;
&lt;P&gt;Anyway, as&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;said, to set the view (zoom) in the newly created viewport, you have to convert the coordinates got from the user in model space UCS to WCS and then, from WCS to the viewport DCS.&lt;/P&gt;
&lt;P&gt;Here's a example adapted from your code which uses an extension method from the &lt;A href="https://github.com/gileCAD/GeometryExtensions" target="_blank" rel="noopener"&gt;GeometryExtensions library&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

using System;

[assembly: CommandClass(typeof(CreateLayoutAndViewportSample.Commands))]

namespace CreateLayoutAndViewportSample
{
    public class Commands
    {
        [CommandMethod("TEST", CommandFlags.NoPaperSpace)]
        public static void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            // Prompt the user to get points
            var promptPointResult = ed.GetPoint("\nFirst corner: ");
            if (promptPointResult.Status != PromptStatus.OK)
                return;
            var ucsPt1 = promptPointResult.Value;

            promptPointResult = ed.GetCorner("\nOpposite corner: ", ucsPt1);
            if (promptPointResult.Status != PromptStatus.OK)
                return;
            var ucsPt2 = promptPointResult.Value;

            // Prompt the user for the Layout name
            var promptResult = ed.GetString("\nLayout name");
            if (promptResult.Status != PromptStatus.OK)
                return;
            string layoutName = promptResult.StringResult;

            var layoutManager = LayoutManager.Current;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                // Delete the layout if it already exists
                var layoutDict = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                if (layoutDict.Contains(layoutName))
                    layoutManager.DeleteLayout(layoutName);

                // Create a new Layout
                var layoutId = layoutManager.CreateLayout(layoutName);
                layoutManager.CurrentLayout = layoutName;

                // Create a Viewport
                var vp = new Viewport();
                vp.SetDatabaseDefaults();
                var wcsPt1 = ucsPt1.TransformBy(ed.CurrentUserCoordinateSystem);
                var wcsPt2 = ucsPt2.TransformBy(ed.CurrentUserCoordinateSystem);
                vp.CenterPoint = new LineSegment3d(wcsPt1, wcsPt2).MidPoint;
                vp.Width = Math.Abs(wcsPt1.X - wcsPt2.X);
                vp.Height = Math.Abs(wcsPt1.Y - wcsPt2.Y);

                var layout = (Layout)tr.GetObject(layoutId, OpenMode.ForRead);
                var btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);
                btr.AppendEntity(vp);
                tr.AddNewlyCreatedDBObject(vp, true);

                // Set the viewport view
                vp.On = true;
                var dcsPt1 = wcsPt1.TransformBy(vp.WCS2DCS());
                var dcsPt2 = wcsPt2.TransformBy(vp.WCS2DCS());
                vp.ViewCenter = new Point2d((dcsPt1.X + dcsPt2.X) * 0.5, (dcsPt1.Y + dcsPt2.Y) * 0.5);
                vp.ViewHeight = Math.Abs(dcsPt1.Y - dcsPt2.Y);
                tr.Commit();
            }
        }
    }
    // Extract from https://github.com/gileCAD/GeometryExtensions
    public static class Extension
    {
        /// &amp;lt;summary&amp;gt;
        /// Gets the transformation matrix of the world coordinate system (WCS)
        /// to the display coordinate system (DCS) of the specified window.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="viewport"&amp;gt;The instance to which this method applies.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;The transformation matrix from WCS to DCS.&amp;lt;/returns&amp;gt;
        /// &amp;lt;exception cref="System.ArgumentNullException"&amp;gt;ArgumentException is thrown if &amp;lt;paramref name="viewport"/&amp;gt; is null.&amp;lt;/exception&amp;gt;
        public static Matrix3d WCS2DCS(this Viewport viewport)
        {
            if (viewport is null)
                throw new System.ArgumentNullException(nameof(viewport));
            return
                Matrix3d.WorldToPlane(viewport.ViewDirection) *
                Matrix3d.Displacement(viewport.ViewTarget.GetAsVector().Negate()) *
                Matrix3d.Rotation(viewport.TwistAngle, viewport.ViewDirection, viewport.ViewTarget);
        }
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Aug 2025 16:41:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13761610#M85589</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2025-08-10T16:41:13Z</dc:date>
    </item>
    <item>
      <title>Ynt: Layout Create</title>
      <link>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13761672#M85590</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I applied the code you gave a little by changing it. But this is not the result I still want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[CommandMethod("LCT2", CommandFlags.NoPaperSpace)]
public void Test()
{
    var (_, db, ed) = GetActiveDocumentComponents();

    // Prompt the user to get points
    var promptPointResult = ed.GetPoint("\nFirst corner: ");
    if (promptPointResult.Status != PromptStatus.OK)
        return;
    var ucsPt1 = promptPointResult.Value;

    promptPointResult = ed.GetCorner("\nOpposite corner: ", ucsPt1);
    if (promptPointResult.Status != PromptStatus.OK)
        return;
    var ucsPt2 = promptPointResult.Value;

    // Prompt the user for the Layout name
    var promptResult = ed.GetString("\nLayout name");
    if (promptResult.Status != PromptStatus.OK)
        return;
    string layoutName = promptResult.StringResult;

    var layoutManager = LayoutManager.Current;

    using (var tr = db.TransactionManager.StartTransaction())
    {
        // Delete the layout if it already exists
        var layoutDict = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
        if (layoutDict.Contains(layoutName))
            layoutManager.DeleteLayout(layoutName);

        // Create a new Layout
        var layoutId = layoutManager.CreateLayout(layoutName);
        layoutManager.CurrentLayout = layoutName;

        // Create a Viewport
        var vp = new Autodesk.AutoCAD.DatabaseServices.Viewport();
        vp.SetDatabaseDefaults();
        var wcsPt1 = ucsPt1.TransformBy(ed.CurrentUserCoordinateSystem);
        var wcsPt2 = ucsPt2.TransformBy(ed.CurrentUserCoordinateSystem);
        //vp.CenterPoint = new LineSegment3d(wcsPt1, wcsPt2).MidPoint;
        vp.Width = Math.Abs(wcsPt1.X - wcsPt2.X);
        vp.Height = Math.Abs(wcsPt1.Y - wcsPt2.Y);
        vp.CenterPoint = new Point3d(vp.Width / 2, vp.Height / 2, 0);

        var layout = (Layout)tr.GetObject(layoutId, OpenMode.ForRead);
        var btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);
        btr.AppendEntity(vp);
        tr.AddNewlyCreatedDBObject(vp, true);

        // Set the viewport view
        vp.On = true;
        var dcsPt1 = wcsPt1.TransformBy(vp.WCS2DCS());
        var dcsPt2 = wcsPt2.TransformBy(vp.WCS2DCS());
        //vp.ViewCenter = new Point2d((dcsPt1.X + dcsPt2.X) * 0.5, (dcsPt1.Y + dcsPt2.Y) * 0.5);
        vp.ViewCenter = new Point2d((dcsPt1.X + dcsPt2.X) / 2, (dcsPt1.Y + dcsPt2.Y) / 2);
        vp.ViewHeight = Math.Abs(dcsPt1.Y - dcsPt2.Y);
        tr.Commit();
    }
}&lt;/LI-CODE&gt;&lt;P&gt;This is the result I get .. Add Picture.&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="END01.jpg" style="width: 557px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1560007i53E5564A484B20E9/image-size/large?v=v2&amp;amp;px=999" role="button" title="END01.jpg" alt="END01.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;****&amp;nbsp; There will be no lower left part appearing in the picture. This will cover the P1 and P2 point ... So only the white part will appear. But in P1 and P2 size. The gray place that appears in the picture on the screen right now will look white ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Aug 2025 18:33:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13761672#M85590</guid>
      <dc:creator>k005</dc:creator>
      <dc:date>2025-08-10T18:33:22Z</dc:date>
    </item>
    <item>
      <title>Ynt: Layout Create</title>
      <link>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13762597#M85591</link>
      <description>&lt;P&gt;Still not sure to fully understand the request.&lt;/P&gt;
&lt;P&gt;This one creates a new layout and&amp;nbsp;a viewport which fills the (default) plotting area and center and zoom the view so that the input rectangle are within the viewport.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[CommandMethod("TEST", CommandFlags.NoPaperSpace)]
public static void Test()
{
    var doc = Application.DocumentManager.MdiActiveDocument;
    var db = doc.Database;
    var ed = doc.Editor;

    // Prompt the user to get points
    var promptPointResult = ed.GetPoint("\nFirst corner: ");
    if (promptPointResult.Status != PromptStatus.OK)
        return;
    var ucsPt1 = promptPointResult.Value;

    promptPointResult = ed.GetCorner("\nOpposite corner: ", ucsPt1);
    if (promptPointResult.Status != PromptStatus.OK)
        return;
    var ucsPt2 = promptPointResult.Value;

    // Prompt the user for the Layout name
    var promptResult = ed.GetString("\nLayout name");
    if (promptResult.Status != PromptStatus.OK)
        return;
    string layoutName = promptResult.StringResult;

    var layoutManager = LayoutManager.Current;

    using (var tr = db.TransactionManager.StartTransaction())
    {
        // Delete the layout if it already exists
        var layoutDict = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
        if (layoutDict.Contains(layoutName))
            layoutManager.DeleteLayout(layoutName);

    // Save and disable LAYOUTCREATEVIEWPORT system variable
    object layoutCreateViewport = Application.GetSystemVariable("LAYOUTCREATEVIEWPORT");
    Application.SetSystemVariable("LAYOUTCREATEVIEWPORT", 0);

        // Create a new Layout (default settings)
        try
        {
            var layoutId = layoutManager.CreateLayout(layoutName);
            layoutManager.CurrentLayout = layoutName;
            var layout = (Layout)tr.GetObject(layoutId, OpenMode.ForRead);
            var btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);

            // Create a Viewport which fits the printable area
            var minPoint = layout.PlotPaperMargins.MinPoint;
            var maxPoint = layout.PlotPaperMargins.MaxPoint;
            var paperSize = layout.PlotPaperSize;
            bool landscape =
                layout.PlotRotation == PlotRotation.Degrees000 ||
                layout.PlotRotation == PlotRotation.Degrees180;
            double viewportWidth =
                landscape ? paperSize.X - maxPoint.X - minPoint.X : paperSize.Y - maxPoint.Y - minPoint.Y;
            double viewportHeight =
                landscape ? paperSize.Y - maxPoint.Y - minPoint.Y : paperSize.X - maxPoint.X - minPoint.X;
            var viewportCenter = new Point3d(viewportWidth * 0.5, viewportHeight * 0.5, 0.0);

            var vp = new Viewport();
            vp.CenterPoint = viewportCenter;
            vp.Width = viewportWidth;
            vp.Height = viewportHeight;
            btr.AppendEntity(vp);
            tr.AddNewlyCreatedDBObject(vp, true);
            vp.On = true;

            // Set the viewport view (center and height) according to model space input points
            var wcsPt1 = ucsPt1.TransformBy(ed.CurrentUserCoordinateSystem);
            var wcsPt2 = ucsPt2.TransformBy(ed.CurrentUserCoordinateSystem);
            var dcsPt1 = wcsPt1.TransformBy(vp.WCS2DCS());
            var dcsPt2 = wcsPt2.TransformBy(vp.WCS2DCS());
            double viewWidth = Math.Abs(dcsPt1.X - dcsPt2.X);
            double viewHeight = Math.Abs(dcsPt1.Y - dcsPt2.Y);
            vp.ViewCenter = new Point2d((dcsPt1.X + dcsPt2.X) * 0.5, (dcsPt1.Y + dcsPt2.Y) * 0.5);
            double ratio = (viewportHeight / viewportWidth) / (viewHeight / viewWidth);
            vp.ViewHeight = ratio &amp;lt;= 1 ? viewHeight : viewHeight * ratio;

            tr.Commit();
        }
        catch (System.Exception ex)
        {
            ed.WriteMessage($"\nError: {ex.Message}");
        }
        finally
        {
            Application.SetSystemVariable("LAYOUTCREATEVIEWPORT", layoutCreateViewport);
        }
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 11 Aug 2025 14:46:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13762597#M85591</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2025-08-11T14:46:37Z</dc:date>
    </item>
    <item>
      <title>Ynt: Layout Create</title>
      <link>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13762777#M85594</link>
      <description>&lt;P&gt;This is not an Autocad part that I use very much ... That's why I can't tell you exactly ... I will find the missing parts and write again here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, Master. &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Aug 2025 15:18:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13762777#M85594</guid>
      <dc:creator>k005</dc:creator>
      <dc:date>2025-08-11T15:18:57Z</dc:date>
    </item>
    <item>
      <title>Ynt: Layout Create</title>
      <link>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13762787#M85595</link>
      <description>&lt;P&gt;Another example that creates a viewport&amp;nbsp;with the same height/width ratio as the input rectangle inside of the printable area.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[CommandMethod("TEST", CommandFlags.NoPaperSpace)]
public static void Test()
{
    var doc = Application.DocumentManager.MdiActiveDocument;
    var db = doc.Database;
    var ed = doc.Editor;

    var ucs = ed.CurrentUserCoordinateSystem;

    // Prompt the user to get points
    var promptPointResult = ed.GetPoint("\nFirst corner: ");
    if (promptPointResult.Status != PromptStatus.OK)
        return;
    var wcsPt1 = promptPointResult.Value.TransformBy(ucs);

    promptPointResult = ed.GetCorner("\nOpposite corner: ", promptPointResult.Value);
    if (promptPointResult.Status != PromptStatus.OK)
        return;
    var wcsPt2 = promptPointResult.Value.TransformBy(ucs);

    // Prompt the user for the Layout name
    var promptResult = ed.GetString("\nLayout name");
    if (promptResult.Status != PromptStatus.OK)
        return;
    string layoutName = promptResult.StringResult;

    var layoutManager = LayoutManager.Current;

    using (var tr = db.TransactionManager.StartTransaction())
    {
        // Delete the layout if it already exists
        var layoutDict = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
        if (layoutDict.Contains(layoutName))
            layoutManager.DeleteLayout(layoutName);

        // Save and disable LAYOUTCREATEVIEWPORT system variable
        object layoutCreateViewport = Application.GetSystemVariable("LAYOUTCREATEVIEWPORT");
        Application.SetSystemVariable("LAYOUTCREATEVIEWPORT", 0);

        // Create a new Layout (default settings)
        try
        {
            var layoutId = layoutManager.CreateLayout(layoutName);
            layoutManager.CurrentLayout = layoutName;
            var layout = (Layout)tr.GetObject(layoutId, OpenMode.ForRead);
            var btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);

            // Create a viewport with the same height/width ratio as the input rectangle
            // that fills the printable area
            var minPoint = layout.PlotPaperMargins.MinPoint;
            var maxPoint = layout.PlotPaperMargins.MaxPoint;
            var paperSize = layout.PlotPaperSize;
            bool landscape =
                layout.PlotRotation == PlotRotation.Degrees000 ||
                layout.PlotRotation == PlotRotation.Degrees180;
            double paperWidth =
                landscape ? paperSize.X - maxPoint.X - minPoint.X : paperSize.Y - maxPoint.Y - minPoint.Y;
            double paperHeight =
                landscape ? paperSize.Y - maxPoint.Y - minPoint.Y : paperSize.X - maxPoint.X - minPoint.X;

            double viewWidth = Math.Abs(wcsPt1.X - wcsPt2.X);
            double viewHeight = Math.Abs(wcsPt1.Y - wcsPt2.Y);
            double ratio = (paperHeight / paperWidth) / (viewHeight / viewWidth);

            var vp = new Viewport();
            vp.CenterPoint = new Point3d(paperWidth * 0.5, paperHeight * 0.5, 0.0);
            if (ratio &amp;lt;= 1)
            {
                vp.Height = paperHeight;
                vp.Width = paperWidth * ratio;
            }
            else
            {
                vp.Width = paperWidth;
                vp.Height = paperHeight / ratio;
            }
                btr.AppendEntity(vp);
            tr.AddNewlyCreatedDBObject(vp, true);
            vp.On = true;

            // Set the viewport view (center and height) according to model space input points
            var dcsPt1 = wcsPt1.TransformBy(vp.WCS2DCS());
            var dcsPt2 = wcsPt2.TransformBy(vp.WCS2DCS());
            vp.ViewCenter = new Point2d((dcsPt1.X + dcsPt2.X) * 0.5, (dcsPt1.Y + dcsPt2.Y) * 0.5);
            vp.ViewHeight = viewHeight;

            tr.Commit();
        }
        catch (System.Exception ex)
        {
            ed.WriteMessage($"\nError: {ex.Message}");
        }
        finally
        {
            Application.SetSystemVariable("LAYOUTCREATEVIEWPORT", layoutCreateViewport);
        }
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Aug 2025 15:30:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13762787#M85595</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2025-08-11T15:30:15Z</dc:date>
    </item>
    <item>
      <title>Ynt: Layout Create</title>
      <link>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13762863#M85599</link>
      <description>&lt;P&gt;Yes.! That's what I want. Thank you very much.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":hugging_face:"&gt;🤗&lt;/span&gt;&amp;nbsp; Health Master.&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Aug 2025 16:39:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layout-create/m-p/13762863#M85599</guid>
      <dc:creator>k005</dc:creator>
      <dc:date>2025-08-11T16:39:27Z</dc:date>
    </item>
  </channel>
</rss>

