The property Autodesk.AutoCAD.GraphicsSystem.View.Viewport has been removed from the AutoCAD .NET 2013 API. You can use the Autodesk.AutoCAD.GraphicsSystem.View.ViewportExtents property instead.
There is a little difference between these two properties though:
Viewport property returned the extents of the viewport in device coordinates (pixels), but ViewportExtents property returns the extents of the viewport in normalized device coordinates.
What does normalized device coordinates mean? In this context, it means that the viewport extents are normalized against the size of the device object containing the viewport. So the approach to get the proper viewport size is as follows:
Device dev = view.Device;
System.Drawing.Size s = dev.Size; //container or window size
Extents2d extents = view.ViewportExtents;
Point2d min_pt = new Point2d(extents.MinPoint.X * s.Width,
extents.MinPoint.Y * s.Height);
Point2d max_pt = new Point2d(extents.MaxPoint.X * s.Width,
extents.MaxPoint.Y * s.Height);
System.Drawing.Rectangle view_rect =
new System.Drawing.Rectangle(
(int)min_pt.X,
(int)min_pt.Y,
(int)System.Math.Abs(max_pt.X - min_pt.X),
(int)System.Math.Abs(max_pt.Y - min_pt.Y));

Leave a Reply