Author Topic: ZoomExtent  (Read 3337 times)

0 Members and 1 Guest are viewing this topic.

cannorth

  • Guest
ZoomExtent
« on: March 02, 2014, 03:10:02 PM »
Hello,

 What is an ObjectArx Vb.Net variation of ZoomExtent method that doesn't use COM.

Thanks,

Cannorth

kaefer

  • Guest
Re: ZoomExtent
« Reply #1 on: March 02, 2014, 04:05:03 PM »
What is an ObjectArx Vb.Net variation of ZoomExtent method that doesn't use COM.

By not wanting COM, I take it that you don't want to invoke a command.

You're familiar with Zoom and Pan the Current View (.NET), the actual code being under Manipulate the Current View (.NET)?


gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: ZoomExtent
« Reply #2 on: March 02, 2014, 04:48:55 PM »
Hi,

Here's a way using extension methods (part of my 'Acad Extensions' library.

Code - C#: [Select]
  1. namespace Autodesk.AutoCAD.EditorInput
  2. {
  3.     public static class EditorExtension
  4.     {
  5.         public static void Zoom(this Editor ed, Extents3d ext)
  6.         {
  7.             if (ed == null)
  8.                 throw new ArgumentNullException("ed");
  9.  
  10.             using (ViewTableRecord view = ed.GetCurrentView())
  11.             {
  12.                 ext.TransformBy(view.WorldToEye());
  13.                 view.Width = ext.MaxPoint.X - ext.MinPoint.X;
  14.                 view.Height = ext.MaxPoint.Y - ext.MinPoint.Y;
  15.                 view.CenterPoint = new Point2d(
  16.                     (ext.MaxPoint.X + ext.MinPoint.X) / 2.0,
  17.                     (ext.MaxPoint.Y + ext.MinPoint.Y) / 2.0);
  18.                 ed.SetCurrentView(view);
  19.             }
  20.         }
  21.  
  22.         public static void ZoomExtents(this Editor ed)
  23.         {
  24.             if (ed == null)
  25.                 throw new ArgumentNullException("ed");
  26.  
  27.             Database db = ed.Document.Database;
  28.             Extents3d ext = (short)Application.GetSystemVariable("cvport") == 1 ?
  29.                 new Extents3d(db.Pextmin, db.Pextmax) :
  30.                 new Extents3d(db.Extmin, db.Extmax);
  31.             ed.Zoom(ext);
  32.         }
  33.     }
  34. }

<EDIT: the ViewTableRecord.WorldToEye() extension method code was missing>

Code - C#: [Select]
  1. using System;
  2. using Autodesk.AutoCAD.Geometry;
  3.  
  4. namespace Autodesk.AutoCAD.DatabaseServices
  5. {
  6.     public static class ViewTableRecordExtension
  7.     {
  8.         public static Matrix3d EyeToWorld(this ViewTableRecord view)
  9.         {
  10.             if (view == null)
  11.                 throw new ArgumentNullException("view");
  12.  
  13.             return
  14.                 Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) *
  15.                 Matrix3d.Displacement(view.Target - Point3d.Origin) *
  16.                 Matrix3d.PlaneToWorld(view.ViewDirection);
  17.         }
  18.  
  19.         public static Matrix3d WorldToEye(this ViewTableRecord view)
  20.         {
  21.             return view.EyeToWorld().Inverse();
  22.         }
  23.     }
  24. }
  25.  
« Last Edit: March 18, 2014, 04:26:36 PM by gile »
Speaking English as a French Frog