To zoom a drawing using the drawing extents. There must be an active viewport in order for the method to work.


public void ZoomExtents(Database database)
{
Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;
ViewTableRecord view = new ViewTableRecord();
Point3d center =
database.Extmin + ((database.Extmax - database.Extmin) / 2);
view.CenterPoint = new Autodesk.AutoCAD.Geometry.Point2d(center.X, center.Y);

view.Height = database.Extmax.Y - database.Extmin.Y;

view.Width = database.Extmax.X - database.Extmin.X;
editor.SetCurrentView(view);
}
 

One Response to AutoCAD: Zooming Extents with C#

  1. DXF File says:

    Thank you for this post. I think I should also learn C#!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Set your Twitter account name in your settings to use the TwitterBar Section.