<?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: Set screen center to my point in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597570#M53574</link>
    <description>&lt;P&gt;I had created new schema and this code works, but still doesn't work in old, stored file.&lt;/P&gt;&lt;P&gt;It's very strange.&lt;/P&gt;&lt;P&gt;It seems in old file I have very specific view but I have no idea what it is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Pavel.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Aug 2012 06:11:36 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-08-28T06:11:36Z</dc:date>
    <item>
      <title>Set screen center to my point</title>
      <link>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597110#M53571</link>
      <description>&lt;P&gt;At this time I tried to set screen center. I have some object and I want to set screen position to this object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I did:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;AcadApplication app = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;&lt;/P&gt;&lt;P&gt;&amp;nbsp;using (Transaction tr = doc.Database.TransactionManager.StartTransaction())&lt;BR /&gt;&amp;nbsp;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Entity en = (Entity)tr.GetObject(objectId, OpenMode.ForRead); // get my obj by Id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Extents3d ext = en.GeometricExtents;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Point3d p_center = new Point3d( // get center&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (ext.MinPoint.X + ext.MaxPoint.X) / 2,&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (ext.MinPoint.Y + ext.MaxPoint.Y) / 2,&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (ext.MinPoint.Z + ext.MaxPoint.Z) / 2&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; // set center point&amp;nbsp;of current view&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ed.UpdateTiledViewportsInDatabase();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ViewportTableRecord viewportTableRec = tr.GetObject(ed.ActiveViewportId, OpenMode.ForWrite) as ViewportTableRecord;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; viewportTableRec.CenterPoint = new Point2d(p_center.X, p_center.Y);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ed.UpdateTiledViewportsFromDatabase();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; // Ok!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tr.Commit();&lt;BR /&gt;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; // set object as selected - it works&lt;/P&gt;&lt;P&gt;&amp;nbsp; doc.Editor.SetImpliedSelection(new ObjectId[] { objectId });&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I see that SetImpliedSelection works fine (as I see current object) but screen center&amp;nbsp; is moved to unknown point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;How I can set screen center to my point?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Pavel.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2012 19:02:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597110#M53571</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-27T19:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Set screen center to my point</title>
      <link>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597222#M53572</link>
      <description>&lt;P&gt;Something like this will do your work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;      Matrix3d ucs = ed.CurrentUserCoordinateSystem;
       Point3d p_center = new Point3d( // get center
                        (ext.MinPoint.X + ext.MaxPoint.X) / 2,
                        (ext.MinPoint.Y + ext.MaxPoint.Y) / 2,
                        (ext.MinPoint.Z + ext.MaxPoint.Z) / 2
       ).TransformBy(ucs);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800000" face="arial,helvetica,sans-serif"&gt;~'J'~&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2012 20:31:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597222#M53572</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-08-27T20:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Set screen center to my point</title>
      <link>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597566#M53573</link>
      <description>&lt;P&gt;No changes&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2012 06:04:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597566#M53573</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-28T06:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Set screen center to my point</title>
      <link>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597570#M53574</link>
      <description>&lt;P&gt;I had created new schema and this code works, but still doesn't work in old, stored file.&lt;/P&gt;&lt;P&gt;It's very strange.&lt;/P&gt;&lt;P&gt;It seems in old file I have very specific view but I have no idea what it is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Pavel.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2012 06:11:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597570#M53574</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-28T06:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Set screen center to my point</title>
      <link>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597732#M53575</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You need to transform the&amp;nbsp;Extents3d from World Coordinates System to the viewport Display Coordinates System before calculating the center point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        private void SetViewCenterToObject(ObjectId id)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            using (Transaction tr = doc.TransactionManager.StartTransaction())
            using (ViewTableRecord view = ed.GetCurrentView())
            {
                Matrix3d DCS2WCS =
                    Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) *
                    Matrix3d.Displacement(view.Target - Point3d.Origin) *
                    Matrix3d.PlaneToWorld(view.ViewDirection);
                Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
                Extents3d ext = ent.GeometricExtents;
                ext.TransformBy(DCS2WCS.Inverse());
                view.CenterPoint = new Point2d(&lt;BR /&gt;                    (ext.MaxPoint.X + ext.MinPoint.X) / 2.0,&lt;BR /&gt;                    (ext.MaxPoint.Y + ext.MinPoint.Y) / 2.0);
                ed.SetCurrentView(view);
                tr.Commit();
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2012 09:00:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597732#M53575</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2012-08-28T09:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Set screen center to my point</title>
      <link>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597812#M53576</link>
      <description>&lt;P&gt;Wow! It works! Thanks, gile!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pavel.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2012 10:52:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/set-screen-center-to-my-point/m-p/3597812#M53576</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-28T10:52:08Z</dc:date>
    </item>
  </channel>
</rss>

