<?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: Create Custom Viewports in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/create-custom-viewports/m-p/4875092#M45093</link>
    <description>&lt;P&gt;It looks to me that the point you passed as view centre point (stPoint) is never chanbed. That is, the following line of code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Point3d stPoint = new Point3d(Convert.ToDouble(CenterLineDataTable.Rows[0]["stx"]), Convert.ToDouble(CenterLineDataTable.Rows[0]["stY"]), 0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ALWAYS gets the first row of the CentreLineDataTable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess is that this line should be placed in the while(true){...} loop and the row index (CenterLineDataTable.Rows[index] should be the sheet count, if there is multiple rows in that table, which staores X and Y values for each sheet's viewport center.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Mar 2014 13:32:34 GMT</pubDate>
    <dc:creator>norman.yuan</dc:creator>
    <dc:date>2014-03-10T13:32:34Z</dc:date>
    <item>
      <title>Create Custom Viewports</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-custom-viewports/m-p/4874894#M45092</link>
      <description>&lt;P&gt;Hi every body.&lt;/P&gt;&lt;P&gt;I'm trying to create some sheets trough a path on a dawing by creating a new Layout for each sheet, and a viewport on it, pointing to a specified point on drawing and have a custom scale. I've been searching so far, and got this:&lt;/P&gt;&lt;PRE&gt;private void Button_runplanning_Click(object sender, EventArgs e)
        {
            using (DocumentLock lck = doc.LockDocument())
            {
                CAD_Additions obj = new CAD_Additions();
                double sheetLength = 500;
                double sheetWidth = 200;
                //Point2dCollection pc2 = new Point2dCollection();
                #region Get centerline object
                Polyline CL = new Polyline();
                try
                {
                    using (Transaction tr = curdb.TransactionManager.StartTransaction())
                    {
                        long val1 = Convert.ToInt64(CenterLineDataTable.Rows[0]["handle"]);
                        ObjectId clid = curdb.GetObjectId(false, new Handle(val1), 0);
                        CL = (Polyline)tr.GetObject(clid, OpenMode.ForRead);
                        tr.Commit();
                    }
                }
                catch (System.Exception exp)
                {
                    RadMessageBox.Show("An error occured. Try again please.\r\n" + exp.Message, "Error", MessageBoxButtons.OK, RadMessageIcon.Error);
                    return;
                }

                if (CL == null)
                {
                    RadMessageBox.Show("An error occured. Try again please.", "Error", MessageBoxButtons.OK, RadMessageIcon.Error);
                    return;
                }
                #endregion
                using (Transaction tr = curdb.TransactionManager.StartTransaction())
                {
                    LayoutManager acLayoutmgr = Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current;
                    Point3d stPoint = new Point3d(Convert.ToDouble(CenterLineDataTable.Rows[0]["stx"]), Convert.ToDouble(CenterLineDataTable.Rows[0]["stY"]), 0);
                    int sheetCount = 0;
                    while (true)
                    {
                        if (CL.GetDistAtPoint(stPoint) + (sheetCount * sheetLength) + sheetLength / 2 &amp;gt; CL.Length)
                        {
                            break;
                        }
                        Point3d sheetCenter = CL.GetPointAtDist(CL.GetDistAtPoint(stPoint) + (sheetCount * sheetLength) + sheetLength / 2);
                        string layoutName = "Layout_" + (sheetCount + 1).ToString();
                        ObjectId newLayoutId = acLayoutmgr.CreateLayout(layoutName);
                        Layout lay = (Layout)tr.GetObject(newLayoutId, OpenMode.ForRead);
                        CreateViewport(lay.ObjectId, sheetCenter, sheetLength, sheetWidth);
                        //EditCurrentViewPort(lay.ObjectId, sheetCenter, sheetLength, sheetWidth);
                        sheetCount++;
                    }
                    tr.Commit();
                }
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public ObjectId CreateViewport(ObjectId layoutId, Point3d center, double length, double width)
        {
            using (DocumentLock lck = doc.LockDocument())
            {
                ObjectId oid;

                try
                {
                    using (Transaction tr = curdb.TransactionManager.StartTransaction())
                    {
                        Layout LayoutDest = (Layout)tr.GetObject(layoutId, OpenMode.ForRead);
                        //Layout LayoutDest = (Layout)tr.GetObject(curdb.CurrentSpaceId, OpenMode.ForRead);
                        BlockTableRecord btrDest = (BlockTableRecord)tr.GetObject(LayoutDest.BlockTableRecordId, OpenMode.ForWrite);

                        Autodesk.AutoCAD.DatabaseServices.Viewport vpNew = new Autodesk.AutoCAD.DatabaseServices.Viewport();
                        vpNew.SetDatabaseDefaults();
                        vpNew.Width = length;
                        vpNew.Height = width;
                        vpNew.CenterPoint = center;
                        vpNew.ViewTarget = center;
                        vpNew.ViewCenter = new Point2d(center.X, center.Y);
                        vpNew.ViewHeight = width;
                        vpNew.Visible = true;
                        vpNew.StandardScale = StandardScaleType.CustomScale;
                        vpNew.CustomScale = 1;
                        oid = btrDest.AppendEntity(vpNew);
                        tr.AddNewlyCreatedDBObject(vpNew, true);

                        vpNew.ViewDirection = Vector3d.ZAxis;
                        vpNew.On = true;

                        tr.Commit();
                        return oid;
                    }
                }
                catch (System.Exception ex)
                {
                    ed.WriteMessage(ex.Message);
                }
            }
            return layoutId;
        }&lt;/PRE&gt;&lt;P&gt;Tthis works without any error, some layouts are created ("Layout_x"), but all of them, have a same viewport pointing to the drawing extents.&lt;/P&gt;&lt;P&gt;Can anyone help me on this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2014 12:02:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-custom-viewports/m-p/4874894#M45092</guid>
      <dc:creator>a.hajihasani</dc:creator>
      <dc:date>2014-03-10T12:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create Custom Viewports</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-custom-viewports/m-p/4875092#M45093</link>
      <description>&lt;P&gt;It looks to me that the point you passed as view centre point (stPoint) is never chanbed. That is, the following line of code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Point3d stPoint = new Point3d(Convert.ToDouble(CenterLineDataTable.Rows[0]["stx"]), Convert.ToDouble(CenterLineDataTable.Rows[0]["stY"]), 0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ALWAYS gets the first row of the CentreLineDataTable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess is that this line should be placed in the while(true){...} loop and the row index (CenterLineDataTable.Rows[index] should be the sheet count, if there is multiple rows in that table, which staores X and Y values for each sheet's viewport center.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2014 13:32:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-custom-viewports/m-p/4875092#M45093</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2014-03-10T13:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create Custom Viewports</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-custom-viewports/m-p/4875190#M45094</link>
      <description>&lt;P&gt;Thank's norman, but that's not exactly what I'm searching for. The first row of the CenterLineDataTable contains data refering to a single polyline object, which user is asked to select it somewhere else, and It's the Center Line which I'm trying to generate and arrange sheets through it.&lt;/P&gt;&lt;P&gt;I tried more, and figured out that its possible to modify a viewport using these codes:&lt;/P&gt;&lt;PRE&gt;string layoutName = "Layout_" + (sheetCount + 1).ToString();
                        ObjectId newLayoutId = acLayoutmgr.CreateLayout(layoutName);
                        Layout lay = (Layout)tr.GetObject(newLayoutId, OpenMode.ForRead);
                        acLayoutmgr.CurrentLayout = layoutName;
                        ObjectIdCollection vptids = lay.GetViewports();
                        for (int i = 0; i &amp;lt; vptids.Count-1; i++)
                        {
                            ObjectId vptid = vptids[i];
                            Viewport vp = (Viewport)tr.GetObject(vptid, OpenMode.ForWrite);
                            //vp.CenterPoint = new Point3d(0, 0, 0);
                            vp.CustomScale = 1;
                            //vp.ViewTarget = new Point3d(.001, .001, 0);
                            //vp.SetUcs(new Point3d(0, 0, 0), new Vector3d(1, 1, 0), new Vector3d(1, -1, 0));
                            //vp.ViewDirection = new Vector3d(1, 1, 0);
                        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;But, which property of the Viewport I should modify to make it point to my desired point?&lt;/P&gt;&lt;P&gt;When I use CenterPoint, or ViewTarget or vp.ViewCenter and pass my desired coordinate components (sheetCenter.X ,sheetCenter.Y) to it, the viewport points to an undesired location (like -3412531,-41143523). Seems that the CenterPoint property referse to the paperspace coordinate system, but is that same for the two others? It looks strange to me. Is that a problem of some USC definition? Or somthing like mismatch in scales? Hmmmm,...&amp;nbsp; I'm confused somewhat. Any help would be useful and appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2014 13:59:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-custom-viewports/m-p/4875190#M45094</guid>
      <dc:creator>a.hajihasani</dc:creator>
      <dc:date>2014-03-10T13:59:31Z</dc:date>
    </item>
  </channel>
</rss>

