using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;//运行时
using Autodesk.AutoCAD.Runtime;//数据库
using Autodesk.AutoCAD.DatabaseServices;//应用程序服务
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Geometry;
namespace AutoDemo9{publicclassClass1{[CommandMethod("ZoomExtents")]publicstaticvoidZoomExtents(){Document acDoc =Application.DocumentManager.MdiActiveDocument;Database acDb =acDoc.Database;acDb.UpdateExt(false);
using (Transaction acTran =acDb.TransactionManager.StartTransaction()){//视图记录表ViewTableRecord acView;//获取当前视图
acView =acDoc.Editor.GetCurrentView();//获取3dPoint3d pMin,pMax;//当前DB库显示范围最大点
pMax =acDb.Extmax;//当前DB库显示范围最小点
pMin =acDb.Extmin;//定义高度宽度double dWidth, dHeight;
dWidth =pMax.X-pMin.X;
dHeight =pMax.Y-pMin.Y;//当前视图的宽度和高度 比值 double dViewRation =acView.Width/acView.Height;if(dWidth>dHeight*dViewRation)dHeight = dWidth / dViewRation;acView.Width= dWidth;acView.Height= dHeight;Point2d pCenter =newPoint2d((pMax.X+pMin.X)/2,(pMax.Y+pMin.Y)/2);//视图中新店 = 模型空间点acView.CenterPoint= pCenter;//更新视图acDoc.Editor.SetCurrentView(acView);//提交事务acTran.Commit();}}}}
空间界限,当前模型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;//运行时
using Autodesk.AutoCAD.Runtime;//数据库
using Autodesk.AutoCAD.DatabaseServices;//应用程序服务
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Geometry;
namespace AutoDemo10{publicclassClass1{[CommandMethod("ZoomLimints")]publicstaticvoidZoomLimints(){//获取当前文档Document acDoc =Application.DocumentManager.MdiActiveDocument;//获取当前数据库Database acDb =acDoc.Database;
using (Transaction acTran =acDb.TransactionManager.StartTransaction()){//当前是图表记录ViewTableRecord acView =acDoc.Editor.GetCurrentView();Point2d pMin, pMax;//获取数据库界限的最大点
pMax =acDb.Limmax;
pMin =acDb.Limmin;//定义高度宽度double dWidth, dHeight;
dWidth =pMax.X-pMin.X;
dHeight =pMax.Y-pMin.Y;//当前比例double dViewRation =acView.Width/acView.Height;if(dWidth > dHeight * dViewRation) dHeight = dWidth / dViewRation;Point2d pCenter;double x =(pMin.X+pMax.X)/2;double y =(pMin.Y+pMax.Y)/2;
pCenter =newPoint2d(x,y);acView.Width= dWidth;acView.Height= dHeight;acView.CenterPoint= pCenter;acDoc.Editor.SetCurrentView(acView);acTran.Commit();}}}}
定义两点范围,缩放到指定区域
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;//运行时
using Autodesk.AutoCAD.Runtime;//数据库
using Autodesk.AutoCAD.DatabaseServices;//应用程序服务
using Autodesk.AutoCAD.ApplicationServices;//几何
using Autodesk.AutoCAD.Geometry;
namespace AutoDemo11{publicclassClass1{[CommandMethod("ZoomTop")]publicstaticvoidZoomLimints(){Point3d p1 =newPoint3d(0,0,0);Point3d p2 =newPoint3d(50,500,0);//获取当前文档Document acDoc =Application.DocumentManager.MdiActiveDocument;//获取当前数据库Database acDb =acDoc.Database;
using (Transaction acTran =acDb.TransactionManager.StartTransaction()){//当前视图表记录ViewTableRecord acView =acDoc.Editor.GetCurrentView();Extents3d eExt;
using (Line line =newLine(p1,p2)){//获取边界值得最大小值
eExt =newExtents3d(line.Bounds.Value.MinPoint,line.Bounds.Value.MaxPoint);}//获取比例double viewR =acView.Width/acView.Height;//定义宽度高度double dWidth, dHeight;//三维范围 最大点减最小点
dWidth =eExt.MaxPoint.X-eExt.MinPoint.X;
dHeight =eExt.MaxPoint.Y-eExt.MinPoint.Y;//如果当前视图宽度大于if(dWidth > dHeight * viewR) dHeight = dWidth / viewR;//声明二维Point2d pC;double x, y;
x =(eExt.MinPoint.X+eExt.MaxPoint.X)/2;
y =(eExt.MinPoint.Y+eExt.MaxPoint.Y)/2;
pC =newPoint2d(x, y);acView.CenterPoint= pC;acView.Width= dWidth;acView.Height= dHeight;acDoc.Editor.SetCurrentView(acView);acTran.Commit();}}}}