<?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: Add new layout this object in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3897571#M49786</link>
    <description>Try calling the Initialize() method of the Layout before you try to do anything with it.</description>
    <pubDate>Mon, 29 Apr 2013 19:04:04 GMT</pubDate>
    <dc:creator>DiningPhilosopher</dc:creator>
    <dc:date>2013-04-29T19:04:04Z</dc:date>
    <item>
      <title>Add new layout this object</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3896872#M49785</link>
      <description>&lt;P&gt;Hi, have a problem.&lt;/P&gt;&lt;P&gt;There is a function that creates a few new layouts.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class="hps"&gt;On&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;each page&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;i want to add&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;viewport, but nothing action.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class="hps"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class="hps"&gt;Insert Layouts&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;[CommandMethod("myAddLayout")]
        public void GenerateLayouts() 
        {
            int layoutCount = this.length / this.layoutLength;
            using (Transaction tr = this.acCurDb.TransactionManager.StartTransaction())
            {
                LayoutManager acLayoutMgr = LayoutManager.Current;
                for (int i = 0; i &amp;lt; layoutCount; i++)
                {
                    // Create the new layout with default settings
                    String layoutName = i * this.layoutLength + " - " + (i + 1) * this.layoutLength;
                    ObjectId newLayoutId = acLayoutMgr.CreateLayout(layoutName);
                    Layout lay = tr.GetObject(newLayoutId, OpenMode.ForRead) as Layout;

                    CreateViewPort(lay.ObjectId);
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Insert ViewPort&lt;/P&gt;&lt;PRE&gt;public void CreateViewPort(ObjectId layoutId)
        {
            using (Transaction tr = this.acCurDb.TransactionManager.StartTransaction())
            {
                Layout layout = tr.GetObject(layoutId, OpenMode.ForRead) as Layout;
                BlockTableRecord acBlkTblRec2 = tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite) as BlockTableRecord;
                
                // Create a Viewport
                Viewport acVport = new Viewport();
                acVport.SetDatabaseDefaults();

                // Add the new object to the block table record and the transaction
                acBlkTblRec2.AppendEntity(acVport);
                tr.AddNewlyCreatedDBObject(acVport, true);

                acVport.ViewDirection = new Vector3d(0, 0, 1);
                // Enable the viewport
                acVport.On = true;

                // Save the new objects to the database
                tr.Commit();
            }     
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;But if call function - CreateViewPort, ViewPort is create on first page.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class="hps"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2013 09:24:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3896872#M49785</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-04-29T09:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Add new layout this object</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3897571#M49786</link>
      <description>Try calling the Initialize() method of the Layout before you try to do anything with it.</description>
      <pubDate>Mon, 29 Apr 2013 19:04:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3897571#M49786</guid>
      <dc:creator>DiningPhilosopher</dc:creator>
      <dc:date>2013-04-29T19:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Add new layout this object</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3897826#M49787</link>
      <description>&lt;PRE&gt;Layout lay = tr.GetObject(newLayoutId, OpenMode.ForRead) as Layout;
lay.Initialize();&lt;/PRE&gt;&lt;P&gt;return error&lt;/P&gt;&lt;P&gt;Error during command executing: 'Unsupported method!'.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2013 00:20:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3897826#M49787</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-04-30T00:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Add new layout this object</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3897864#M49788</link>
      <description>&lt;P&gt;Layout is copy ok.&lt;/P&gt;&lt;P&gt;I have error on insert only ViewPort to new layout.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2013 03:22:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3897864#M49788</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-04-30T03:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Add new layout this object</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3904509#M49789</link>
      <description>&lt;P&gt;As DP had mentioned, layout is to be initialized and it can be done by switching to it by making it current.&lt;/P&gt;
&lt;P&gt;Here is a code snippet that uses"CurrentLayout" before creating the paperspace viewport.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also refer to this document for a&amp;nbsp;code sample to create paperspace viewport :&lt;/P&gt;
&lt;P&gt;&lt;A href="http://docs.autodesk.com/CIV3D/2012/ENU/filesMDG/WS1a9193826455f5ff2566ffd511ff6f8c7ca-343a.htm" target="_blank"&gt;http://docs.autodesk.com/CIV3D/2012/ENU/filesMDG/WS1a9193826455f5ff2566ffd511ff6f8c7ca-343a.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;[CommandMethod("AddLayout")]
public void AddLayoutMethod() 
{
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    Database db = Application.DocumentManager.MdiActiveDocument.Database;

    int layoutCount = 3;
    int layoutLength = 3;
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        LayoutManager acLayoutMgr = LayoutManager.Current;
        for (int i = 0; i &amp;lt; layoutCount; i++)
        {
            String layoutName = i * layoutLength + " - " + (i + 1) * layoutLength;

            ObjectId newLayoutId = acLayoutMgr.CreateLayout(layoutName);
            Layout lay = tr.GetObject(newLayoutId, OpenMode.ForRead) as Layout;

            LayoutManager.Current.CurrentLayout = layoutName;

            CreateViewport(lay.ObjectId);
        }
        tr.Commit();
    }
}

public void CreateViewport(ObjectId layoutId)
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    ObjectId oid;

    try
    {
        using (Transaction Tx = db.TransactionManager.StartTransaction())
        {
            Layout LayoutDest = (Layout)Tx.GetObject(layoutId, OpenMode.ForRead);
            BlockTableRecord btrDest = (BlockTableRecord)Tx.GetObject(LayoutDest.BlockTableRecordId, OpenMode.ForWrite);

            Autodesk.AutoCAD.DatabaseServices.Viewport vpNew = new Autodesk.AutoCAD.DatabaseServices.Viewport();
            vpNew.SetDatabaseDefaults();
            vpNew.Width = 6.0;
            vpNew.Height = 5.0;
            vpNew.CenterPoint = new Point3d(3.25, 3, 0);

            oid = btrDest.AppendEntity(vpNew);
            Tx.AddNewlyCreatedDBObject(vpNew, true);

            vpNew.ViewDirection = Vector3d.ZAxis;
            vpNew.On = true;
                    
            Tx.Commit();
        }
    }
    catch (System.Exception ex)
    {
        ed.WriteMessage(ex.Message);
    }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2013 09:44:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3904509#M49789</guid>
      <dc:creator>Balaji_Ram</dc:creator>
      <dc:date>2013-05-03T09:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Add new layout this object</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3911035#M49790</link>
      <description>&lt;P&gt;Hi &lt;STRONG&gt;Balaji&lt;/STRONG&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to display an area in model at selected viewport?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank so much,&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2013 05:47:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3911035#M49790</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-05-07T05:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: Add new layout this object</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3914899#M49791</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Viewport parameters such as "ViewHeight", "ViewTarget", "ViewDirection", "TwistAngle" and "ViewCenter" govern the part of the model space that you see in the viewport. Setting appropriate values for it will change the area of the model space that you see in the viewport.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a sample code to set the viewport parameters such that it shows what you see in the model space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Document activeDoc = Application.DocumentManager.MdiActiveDocument;
Database db = activeDoc.Database;
Editor ed = activeDoc.Editor;

PromptEntityOptions peo = new PromptEntityOptions("Select a viewport : ");
peo.SetRejectMessage("Select a viewport.");
peo.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Viewport), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
{
    ed.WriteMessage("Nothing selected. Please run the command again.");
    return;
}

ObjectId oid = per.ObjectId;

using (Transaction tr = db.TransactionManager.StartTransaction())
{
    ViewportTable vt = tr.GetObject(db.ViewportTableId, OpenMode.ForRead) as ViewportTable;
    ViewportTableRecord vtr = tr.GetObject(vt["*Active"], OpenMode.ForWrite) as ViewportTableRecord;
    Autodesk.AutoCAD.DatabaseServices.Viewport vp
        = tr.GetObject(oid, OpenMode.ForWrite) as Autodesk.AutoCAD.DatabaseServices.Viewport;

    if (vtr != null &amp;amp;&amp;amp; vp != null)
    {
        vp.ViewHeight = vtr.Height;
        vp.ViewTarget = vtr.Target;
        vp.ViewDirection = vtr.ViewDirection;
        vp.TwistAngle = vtr.ViewTwist;
        vp.ViewCenter = vtr.CenterPoint;
    }
    tr.Commit();
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2013 08:29:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3914899#M49791</guid>
      <dc:creator>Balaji_Ram</dc:creator>
      <dc:date>2013-05-09T08:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Add new layout this object</title>
      <link>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3921345#M49792</link>
      <description>&lt;P&gt;Thanks so much&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2013 10:23:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/add-new-layout-this-object/m-p/3921345#M49792</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-05-14T10:23:44Z</dc:date>
    </item>
  </channel>
</rss>

