public static void ZoomToExtents(this Database database) { using (DBObject dbObj = GetActiveViewportId(database).GetObject(OpenMode.ForWrite)) { // using protocol extensions we handle PS and MS viewports in the same manner using (AbstractViewportData viewportData = new AbstractViewportData(dbObj)) { using (Teigha.GraphicsSystem.View view = viewportData.GsView) { // do actual zooming - change GS view using (AbstractViewPE viewPE = new AbstractViewPE(view)) { BoundBlock3d boundBlock = new BoundBlock3d(); bool bBboxValid = viewPE.GetViewExtents(boundBlock); // paper space overall view if (dbObj is Viewport && ((Viewport)dbObj).Number == 1) { if (!bBboxValid || !(boundBlock.GetMinimumPoint().X < boundBlock.GetMaximumPoint().X&& boundBlock.GetMinimumPoint().Y < boundBlock.GetMaximumPoint().Y)) { bBboxValid = GetLayoutExtents(database, view, ref boundBlock); } } else if (!bBboxValid) // model space viewport { bBboxValid = GetLayoutExtents(database, view, ref boundBlock); } if (!bBboxValid) { // set to somewhat reasonable (e.g. paper size) if (database.Measurement == MeasurementValue.Metric) { boundBlock.Set(Point3d.Origin, new Point3d(297.0, 210.0, 0.0)); // set to papersize ISO A4 (portrait) } else { boundBlock.Set(Point3d.Origin, new Point3d(11.0, 8.5, 0.0)); // ANSI A (8.50 x 11.00) (landscape) } boundBlock.TransformBy(view.ViewingMatrix); } viewPE.ZoomExtents(boundBlock); boundBlock.Dispose(); } // save changes to database viewportData.SetView(view); } } } }
void zoom_extents(Teigha.GraphicsSystem.View pView, DBObject pVpObj) { // here protocol extension is used again, that provides some helpful functions using (AbstractViewPE pVpPE = new AbstractViewPE(pView)) { BoundBlock3d bbox = new BoundBlock3d(); bool bBboxValid = pVpPE.GetViewExtents(bbox); // paper space overall view if (pVpObj is Teigha.DatabaseServices.Viewport && ((Teigha.DatabaseServices.Viewport)pVpObj).Number == 1) { if (!bBboxValid || !(bbox.GetMinimumPoint().X < bbox.GetMaximumPoint().X&& bbox.GetMinimumPoint().Y < bbox.GetMaximumPoint().Y)) { bBboxValid = get_layout_extents(database, pView, ref bbox); } } else if (!bBboxValid) // model space viewport { bBboxValid = get_layout_extents(database, pView, ref bbox); } if (!bBboxValid) { // set to somewhat reasonable (e.g. paper size) if (database.Measurement == MeasurementValue.Metric) { bbox.Set(Point3d.Origin, new Point3d(297.0, 210.0, 0.0)); // set to papersize ISO A4 (portrait) } else { bbox.Set(Point3d.Origin, new Point3d(11.0, 8.5, 0.0)); // ANSI A (8.50 x 11.00) (landscape) } bbox.TransformBy(pView.ViewingMatrix); } pVpPE.ZoomExtents(bbox); } }
public static void Zoom(this Database database, BoundBlock3d box) { using (var vtr = (ViewportTableRecord)database.CurrentViewportTableRecordId.GetObject(OpenMode.ForWrite)) { // using protocol extensions we handle PS and MS viewports in the same manner using (var vpd = new AbstractViewportData(vtr)) { var view = vpd.GsView; // do actual zooming - change GS view // here protocol extension is used again, that provides some helpful functions using (var vpe = new AbstractViewPE(view)) { using (BoundBlock3d boundBlock3D = (BoundBlock3d)box.Clone()) { boundBlock3D.TransformBy(view.ViewingMatrix); vpe.ZoomExtents(boundBlock3D); } } vpd.SetView(view); } } //ReSize(); }