<?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 Named View - ViewTwist Problems?? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3591740#M53928</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The CenterPoint of the ViewtableRecord is to be provided in DCS. In the below sample code, I set the view width and height for the&amp;nbsp;current view. I then perform the transformation of the center point&amp;nbsp;from UCS to DCS and set it as the centerpoint of the viewtable record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;[CommandMethod("VM")]
public static void NamedView()
{
    // Test Values for Named View
    string viewname = "100 m";
    double width = 420;
    double height = 297;
    double angle = 0;

    Document doc = Application.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    Database db = doc.Database;

    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
        BlockTableRecord ms = (BlockTableRecord)tr.GetObject(
            bt[BlockTableRecord.ModelSpace],
            OpenMode.ForWrite);

        // Catch last entity (MVF Block) and align UCS
        ObjectId ent = Autodesk.AutoCAD.Internal.Utils.EntLast();

        if (ent.ObjectClass.DxfName == "INSERT")
        {
            BlockReference blk = (BlockReference)tr.GetObject(ent, OpenMode.ForRead);
            ed.CurrentUserCoordinateSystem = blk.BlockTransform;
            angle = blk.Rotation;
        }
        else
        {
            ed.WriteMessage("Last entity was not a block reference");
            return;
        }

        // Get Current coordinate system
        CoordinateSystem3d cs = ed.CurrentUserCoordinateSystem.CoordinateSystem3d;
        Point3d ucsOrigin = cs.Origin; // Used later for View Origin creation

        //==================================================================
        // Create New User UCS
        //==================================================================

        UcsTable ut = (UcsTable)tr.GetObject(db.UcsTableId, OpenMode.ForRead);
        UcsTableRecord utr;

        if (ut.Has(viewname))
        {
            utr = (UcsTableRecord)tr.GetObject(
                ut[viewname], OpenMode.ForWrite);
        }
        else
        {
            utr = new UcsTableRecord();
            utr.Name = viewname;
            ut.UpgradeOpen();
            ut.Add(utr);
            tr.AddNewlyCreatedDBObject(utr, true);
        }


        utr.Origin = ucsOrigin;
        utr.XAxis = cs.Xaxis;
        utr.YAxis = cs.Yaxis;

        ViewportTableRecord vptr = tr.GetObject(doc.Editor.ActiveViewportId,
            OpenMode.ForWrite) as ViewportTableRecord;

        vptr.IconAtOrigin = true;
        vptr.IconEnabled = true;

        vptr.SetUcs(utr.ObjectId);
        doc.Editor.UpdateTiledViewportsFromDatabase();

        //==================================================================
        // Create View
        //==================================================================

        ViewTable vt = (ViewTable)tr.GetObject(db.ViewTableId, OpenMode.ForRead);
        ViewTableRecord vtr;

        // Check if View Name exists
        if (vt.Has(viewname))
        {
            vtr = tr.GetObject(vt[viewname], OpenMode.ForWrite) as ViewTableRecord;
        }
        else
        {
            vtr = new ViewTableRecord();
            vtr.Name = viewname;
            vt.UpgradeOpen();
            ObjectId vtId = vt.Add(vtr);
            tr.AddNewlyCreatedDBObject(vtr, true);
        }

        // Calculate center point if view
        double centerX = width / 2;
        double centerY = height / 2;
        Point2d ctr = new Point2d(centerX, centerY);

        //Convert to ucs origin to Point2d
        Point2d viewOrigin = new Point2d(ucsOrigin.X, ucsOrigin.Y);

        //Create a rotation Matrix for X and Y Axis
        Matrix2d mat = Matrix2d.Rotation(angle, Point2d.Origin);
        Matrix2d mat2d = new Matrix2d();
        mat2d = Matrix2d.AlignCoordinateSystem(
            Point2d.Origin,
            Vector2d.XAxis,
            Vector2d.YAxis,
            viewOrigin,
            new Vector2d(1, 0).TransformBy(mat),
            new Vector2d(0, 1).TransformBy(mat)
            );

        vtr.ViewTwist = -angle;
        vtr.IsPaperspaceView = false;
        vtr.SetUcs(utr.ObjectId);
        vtr.Height = height;
        vtr.Width = width;

        // Set new view to current
        ed.SetCurrentView(vtr);

		//////////////////////////////////////////////////////////////////////////////////////////////////////////////
		//// Set the CenterPoint of the VTR in DCS
		ResultBuffer ucs = new ResultBuffer(new TypedValue(5003, 1));    // UCS
		ResultBuffer dcs = new ResultBuffer(new TypedValue(5003, 2));    // DCS

		Point3d viewCenter3d_ucs = new Point3d(ctr.X, ctr.Y, 0.0);
		double[] fromPt = viewCenter3d_ucs.ToArray();
		double[] toPt = new double[] { 0, 0, 0 };
		acedTrans(fromPt, ucs.UnmanagedObject, dcs.UnmanagedObject, 0, toPt);
		Point3d viewCenter3d_dcs = new Point3d(toPt[0], toPt[1], toPt[2]);

		vtr.CenterPoint = new Point2d(viewCenter3d_dcs.X, viewCenter3d_dcs.Y); 
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////


        //==================================================================
        // Create Polyline test geometry
        //==================================================================

        // Defined bouding box to new View
        Point2d pt1 = new Point2d(0, 0);
        Point2d pt2 = new Point2d(width, 0);
        Point2d pt3 = new Point2d(width, height);
        Point2d pt4 = new Point2d(0, height);

        Point2d[] pts = { pt1, pt2, pt3, pt4 };

        // Define Polyline Vertices
        Polyline pl = new Polyline(4);

        int max = pts.GetUpperBound(0);

        for (int i = 0; i &amp;lt;= max; i++)
        {
            int j = (i == max ? 0 : i + 1);
            pl.AddVertexAt(i, pts[j].TransformBy(mat2d), 0, 0, 0);
        }
        pl.Closed = true;

        // Add the boundary to modelspace
        ObjectId id = ms.AppendEntity(pl);
        tr.AddNewlyCreatedDBObject(pl, true);

        tr.Commit();
    }
}&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Aug 2012 20:51:50 GMT</pubDate>
    <dc:creator>Balaji_Ram</dc:creator>
    <dc:date>2012-08-22T20:51:50Z</dc:date>
    <item>
      <title>Create Named View - ViewTwist Problems??</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3573012#M53924</link>
      <description>&lt;DIV class="inner"&gt;Hi, I'm trying to create a function that creates a ucs, defines a named view and algins to the current view based on a blockreference (in this case it will be the last selected entity). So far everythings working except I can't get the view to rotate or "twist" properly? Can you have a look to see where I'm going wrong. Here's the full code, the polyline that's created should frame the view.&lt;BR /&gt;&lt;BR /&gt;[CommandMethod("VM")]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; public static void NamedView()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Test Values for Named View&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string viewname = "100 m";&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; double width = 420;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; double height = 297;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; double angle = 0;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Document doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Editor ed = doc.Editor;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Database db = doc.Database;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (Transaction tr = db.TransactionManager.StartTransaction())&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BlockTableRecord ms = (BlockTableRecord)tr.GetObject(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bt[BlockTableRecord.ModelSpace],&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; OpenMode.ForWrite);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Catch last entity (MVF Block) and align UCS&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ObjectId ent = Autodesk.AutoCAD.Internal.Utils.EntLast();&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (ent.ObjectClass.DxfName == "INSERT")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BlockReference blk = (BlockReference)tr.GetObject(ent, OpenMode.ForRead);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ed.CurrentUserCoordinateSystem = blk.BlockTransform;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; angle = blk.Rotation;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ed.WriteMessage("Last entity was not a block reference");&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Get Current coordinate system&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CoordinateSystem3d cs = ed.CurrentUserCoordinateSystem.CoordinateSystem3d;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Point3d ucsOrigin = cs.Origin; // Used later for View Origin creation&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //==================================================================&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Create New User UCS&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //==================================================================&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; UcsTable ut = (UcsTable)tr.GetObject(db.UcsTableId, OpenMode.ForRead);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; UcsTableRecord utr;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (ut.Has(viewname))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; utr = (UcsTableRecord)tr.GetObject(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ut[viewname], OpenMode.ForWrite);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; utr = new UcsTableRecord();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; utr.Name = viewname;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ut.UpgradeOpen();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ut.Add(utr);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; tr.AddNewlyCreatedDBObject(utr, true);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; utr.Origin = ucsOrigin;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; utr.XAxis = cs.Xaxis;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; utr.YAxis = cs.Yaxis;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ViewportTableRecord vptr = tr.GetObject(doc.Editor.ActiveViewportId,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; OpenMode.ForWrite) as ViewportTableRecord;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vptr.IconAtOrigin = true;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vptr.IconEnabled = true;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vptr.SetUcs(utr.ObjectId);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; doc.Editor.UpdateTiledViewportsFromDatabase();&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //==================================================================&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Create View&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //==================================================================&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ViewTable vt = (ViewTable)tr.GetObject(db.ViewTableId, OpenMode.ForRead);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ViewTableRecord vtr;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Check if View Name exit's&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (vt.Has(viewname))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vtr = (ViewTableRecord)tr.GetObject(vt[viewname], OpenMode.ForWrite);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vtr = new ViewTableRecord();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vtr.Name = viewname;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vt.UpgradeOpen();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ObjectId vtId = vt.Add(vtr);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; tr.AddNewlyCreatedDBObject(vtr, true);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Calculate center point if view&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; double centerX = width / 2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; double centerY = height / 2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Point2d ctr = new Point2d(centerX, centerY);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Convert to ucs origin to Point2d&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Point2d viewOrigin = new Point2d(ucsOrigin.X, ucsOrigin.Y);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Create a rotation Matrix for X and Y Axis&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Matrix2d mat = Matrix2d.Rotation(angle, Point2d.Origin);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Matrix2d mat2d = new Matrix2d();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mat2d = Matrix2d.AlignCoordinateSystem(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Point2d.Origin,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Vector2d.XAxis,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Vector2d.YAxis,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; viewOrigin,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new Vector2d(1, 0).TransformBy(mat),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new Vector2d(0, 1).TransformBy(mat)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; );&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Point2d viewCenter = ctr.TransformBy(mat2d);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vtr.ViewTwist = -angle;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vtr.IsPaperspaceView = false;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vtr.CenterPoint = viewCenter;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vtr.SetUcs(utr.ObjectId);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vtr.Height = height;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vtr.Width = width;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Set new view to current&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ed.SetCurrentView(vtr);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //==================================================================&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Create Polyline test geometry&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //==================================================================&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Defined bouding box to new View&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Point2d pt1 = new Point2d(0, 0);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Point2d pt2 = new Point2d(width, 0);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Point2d pt3 = new Point2d(width, height);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Point2d pt4 = new Point2d(0, height);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Point2d[] pts = { pt1, pt2, pt3, pt4 };&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Define Polyline Vertices&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Polyline pl = new Polyline(4);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int max = pts.GetUpperBound(0);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (int i = 0; i &amp;lt;= max; i++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int j = (i == max ? 0 : i + 1);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pl.AddVertexAt(i, pts&lt;EM&gt;.TransformBy(mat2d), 0, 0, 0);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pl.Closed = true;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Add the boundary to modelspace&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ObjectId id = ms.AppendEntity(pl);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; tr.AddNewlyCreatedDBObject(pl, true);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; tr.Commit();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/EM&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Aug 2012 22:31:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3573012#M53924</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-09T22:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create Named View - ViewTwist Problems??</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3581356#M53925</link>
      <description>&lt;P&gt;Can anyone help, still no closer to fixing this problem. Cheers&lt;/P&gt;</description>
      <pubDate>Wed, 15 Aug 2012 23:48:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3581356#M53925</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-15T23:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create Named View - ViewTwist Problems??</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3583024#M53926</link>
      <description>&lt;P&gt;Well, I'm guessing there was an error introduced by the copy/paste operation, as this needed correcting:&lt;/P&gt;
&lt;P&gt;pl.AddVertexAt(i, pts.TransformBy(mat2d), 0, 0, 0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to this:&lt;/P&gt;
&lt;P&gt;pl.AddVertexAt(i, pts[j].TransformBy(mat2d), 0, 0, 0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But once that was done, it appears to work fine as far as the rotation goes. It's not centering the view on the polyline or the blockreference, but I'm not sure if it's supposed to be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this image, the dashed line is the edge of the drawing canvas when the created view is is current. But, the UCS and code generated polyline appear to match the rotation of the water valve block which was inserted with a rotation of 33 degrees.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://forums.autodesk.com/t5/image/serverpage/image-id/35452iC0F84E9BDAD728AD/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="8-15-2012 8-28-19 PM.png" title="8-15-2012 8-28-19 PM.png" align="center" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps you track down what you are looking for.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2012 03:31:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3583024#M53926</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2012-08-16T03:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create Named View - ViewTwist Problems??</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3583034#M53927</link>
      <description>&lt;P&gt;Hi thanks for the reply not sure how that happened? however part I need help with is how to&amp;nbsp;center the view within the polyline. this is what happens when I edit the boundaries of the named view create "100 m"&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;P&gt;&lt;IMG align="center" border="0" title="viewstuff" src="https://forums.autodesk.com/t5/image/serverpage/image-id/35454iFA4D5B157E22A044/image-size/original?v=mpbl-1&amp;amp;px=-1" alt="viewstuff" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the Yellow line is the block, the white is the polyline created on the VM command and the black rectangle is the boundaries of "100 m" view?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want this to be centered within the polyline?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I remove the vtr.viewtwist line the view is centered wwithin the polyline but the rotations out....if I uncomment this line I get the above result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2012 03:49:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3583034#M53927</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-16T03:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create Named View - ViewTwist Problems??</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3591740#M53928</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The CenterPoint of the ViewtableRecord is to be provided in DCS. In the below sample code, I set the view width and height for the&amp;nbsp;current view. I then perform the transformation of the center point&amp;nbsp;from UCS to DCS and set it as the centerpoint of the viewtable record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;[CommandMethod("VM")]
public static void NamedView()
{
    // Test Values for Named View
    string viewname = "100 m";
    double width = 420;
    double height = 297;
    double angle = 0;

    Document doc = Application.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    Database db = doc.Database;

    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
        BlockTableRecord ms = (BlockTableRecord)tr.GetObject(
            bt[BlockTableRecord.ModelSpace],
            OpenMode.ForWrite);

        // Catch last entity (MVF Block) and align UCS
        ObjectId ent = Autodesk.AutoCAD.Internal.Utils.EntLast();

        if (ent.ObjectClass.DxfName == "INSERT")
        {
            BlockReference blk = (BlockReference)tr.GetObject(ent, OpenMode.ForRead);
            ed.CurrentUserCoordinateSystem = blk.BlockTransform;
            angle = blk.Rotation;
        }
        else
        {
            ed.WriteMessage("Last entity was not a block reference");
            return;
        }

        // Get Current coordinate system
        CoordinateSystem3d cs = ed.CurrentUserCoordinateSystem.CoordinateSystem3d;
        Point3d ucsOrigin = cs.Origin; // Used later for View Origin creation

        //==================================================================
        // Create New User UCS
        //==================================================================

        UcsTable ut = (UcsTable)tr.GetObject(db.UcsTableId, OpenMode.ForRead);
        UcsTableRecord utr;

        if (ut.Has(viewname))
        {
            utr = (UcsTableRecord)tr.GetObject(
                ut[viewname], OpenMode.ForWrite);
        }
        else
        {
            utr = new UcsTableRecord();
            utr.Name = viewname;
            ut.UpgradeOpen();
            ut.Add(utr);
            tr.AddNewlyCreatedDBObject(utr, true);
        }


        utr.Origin = ucsOrigin;
        utr.XAxis = cs.Xaxis;
        utr.YAxis = cs.Yaxis;

        ViewportTableRecord vptr = tr.GetObject(doc.Editor.ActiveViewportId,
            OpenMode.ForWrite) as ViewportTableRecord;

        vptr.IconAtOrigin = true;
        vptr.IconEnabled = true;

        vptr.SetUcs(utr.ObjectId);
        doc.Editor.UpdateTiledViewportsFromDatabase();

        //==================================================================
        // Create View
        //==================================================================

        ViewTable vt = (ViewTable)tr.GetObject(db.ViewTableId, OpenMode.ForRead);
        ViewTableRecord vtr;

        // Check if View Name exists
        if (vt.Has(viewname))
        {
            vtr = tr.GetObject(vt[viewname], OpenMode.ForWrite) as ViewTableRecord;
        }
        else
        {
            vtr = new ViewTableRecord();
            vtr.Name = viewname;
            vt.UpgradeOpen();
            ObjectId vtId = vt.Add(vtr);
            tr.AddNewlyCreatedDBObject(vtr, true);
        }

        // Calculate center point if view
        double centerX = width / 2;
        double centerY = height / 2;
        Point2d ctr = new Point2d(centerX, centerY);

        //Convert to ucs origin to Point2d
        Point2d viewOrigin = new Point2d(ucsOrigin.X, ucsOrigin.Y);

        //Create a rotation Matrix for X and Y Axis
        Matrix2d mat = Matrix2d.Rotation(angle, Point2d.Origin);
        Matrix2d mat2d = new Matrix2d();
        mat2d = Matrix2d.AlignCoordinateSystem(
            Point2d.Origin,
            Vector2d.XAxis,
            Vector2d.YAxis,
            viewOrigin,
            new Vector2d(1, 0).TransformBy(mat),
            new Vector2d(0, 1).TransformBy(mat)
            );

        vtr.ViewTwist = -angle;
        vtr.IsPaperspaceView = false;
        vtr.SetUcs(utr.ObjectId);
        vtr.Height = height;
        vtr.Width = width;

        // Set new view to current
        ed.SetCurrentView(vtr);

		//////////////////////////////////////////////////////////////////////////////////////////////////////////////
		//// Set the CenterPoint of the VTR in DCS
		ResultBuffer ucs = new ResultBuffer(new TypedValue(5003, 1));    // UCS
		ResultBuffer dcs = new ResultBuffer(new TypedValue(5003, 2));    // DCS

		Point3d viewCenter3d_ucs = new Point3d(ctr.X, ctr.Y, 0.0);
		double[] fromPt = viewCenter3d_ucs.ToArray();
		double[] toPt = new double[] { 0, 0, 0 };
		acedTrans(fromPt, ucs.UnmanagedObject, dcs.UnmanagedObject, 0, toPt);
		Point3d viewCenter3d_dcs = new Point3d(toPt[0], toPt[1], toPt[2]);

		vtr.CenterPoint = new Point2d(viewCenter3d_dcs.X, viewCenter3d_dcs.Y); 
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////


        //==================================================================
        // Create Polyline test geometry
        //==================================================================

        // Defined bouding box to new View
        Point2d pt1 = new Point2d(0, 0);
        Point2d pt2 = new Point2d(width, 0);
        Point2d pt3 = new Point2d(width, height);
        Point2d pt4 = new Point2d(0, height);

        Point2d[] pts = { pt1, pt2, pt3, pt4 };

        // Define Polyline Vertices
        Polyline pl = new Polyline(4);

        int max = pts.GetUpperBound(0);

        for (int i = 0; i &amp;lt;= max; i++)
        {
            int j = (i == max ? 0 : i + 1);
            pl.AddVertexAt(i, pts[j].TransformBy(mat2d), 0, 0, 0);
        }
        pl.Closed = true;

        // Add the boundary to modelspace
        ObjectId id = ms.AppendEntity(pl);
        tr.AddNewlyCreatedDBObject(pl, true);

        tr.Commit();
    }
}&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2012 20:51:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3591740#M53928</guid>
      <dc:creator>Balaji_Ram</dc:creator>
      <dc:date>2012-08-22T20:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create Named View - ViewTwist Problems??</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3800341#M53929</link>
      <description>&lt;P&gt;Same idea, slightly different approach for anyone interested&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Matrix3d WCS2DCS =&lt;BR /&gt;Matrix3d&lt;BR /&gt;.PlaneToWorld(vtr.ViewDirection)&lt;BR /&gt;.PreMultiplyBy(Matrix3d.Displacement(vtr.Target - Point3d.Origin))&lt;BR /&gt;.PreMultiplyBy(Matrix3d.Rotation(-vtr.ViewTwist, vtr.ViewDirection, vtr.Target))&lt;BR /&gt;.Inverse();&lt;BR /&gt;Point3d viewCenter = blk.Position.TransformBy(WCS2DCS);&lt;BR /&gt;vtr.CenterPoint = new Point2d(viewCenter.X + width / 2.0, viewCenter.Y + height / 2.0);&lt;BR /&gt;&lt;BR /&gt;vtr.SetUcs(utr.ObjectId);&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2013 21:21:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-named-view-viewtwist-problems/m-p/3800341#M53929</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-03-08T21:21:02Z</dc:date>
    </item>
  </channel>
</rss>

