视图操作类,缩放
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports System.Text
Imports System.Linq
Imports System.Collections.Generic
Imports System
''' <summary>
'''
''' desc:视图操作类,缩放
''' auth:LYK
''' date:2017/12/11 10:36:26
'''
''' </summary>
Namespace CadTool
Public NotInheritable Class ViewTableTools
Private Sub New()
End Sub
''' <summary>
''' 实现视图的比例缩放
''' </summary>
''' <param name="ed"></param>
''' <param name="scale">缩放比例</param>
<System.Runtime.CompilerServices.Extension> _
Public Shared Sub ZoomScaled(ed As Editor, scale As Double)
'得到当前视图
'ViewTableRecord view = ed.GetCurrentView();
'view.Width /= scale;
'view.Height /= scale;
Dim 更新当前视图 As 修改视图的宽度和高度
'ed.SetCurrentView(view);
acadApplication.ZoomScaled(scale, AcZoomScaleType.acZoomScaledRelative)
End Sub
Private Shared acadApplication As AcadApplication = CType(Application.AcadApplication, AcadApplication)
''' <summary>
''' 实现视图的窗口缩放
''' </summary>
''' <param name="ed"></param>
''' <param name="pt1">窗口角点</param>
''' <param name="pt2">窗口角点</param>
<System.Runtime.CompilerServices.Extension> _
Public Shared Sub ZoomWindow(ed As Editor, pt1 As Point3d, pt2 As Point3d)
Dim doubles1 As Double() = New Double(2) {pt1.X, pt1.Y, pt1.Z}
Dim doubles2 As Double() = New Double(2) {pt2.X, pt2.Y, pt2.Z}
'参数要求是双精度的数组
acadApplication.ZoomWindow(doubles1, doubles2)
'创建一临时的直线用于获取两点表示的范围
'using (Line line = new Line(pt1, pt2))
'{
' 获取两点表示的范围
' //Extents3d extents = new Extents3d(line.GeomExtents.MinPoint, line.GeomExtents.MaxPoint);
' 获取范围内的最小值点及最大值点
' //Point2d minPt = new Point2d(extents.MinPoint.X, extents.MinPoint.Y);
' //Point2d maxPt = new Point2d(extents.MaxPoint.X, extents.MaxPoint.Y);
' 得到当前视图
' //ViewTableRecord view = new ViewTableRecord();
' 设置视图的中心点、高度和宽度
' //view.CenterPoint = minPt + (maxPt - minPt) / 2;
' view.Height = maxPt.Y - minPt.Y;
' view.Width = maxPt.X - minPt.X;
' //view.Height = maxPt.Y - minPt.Y + 10;
' //view.Width = maxPt.X - minPt.X + 10;
' 更新当前视图
' ed.SetCurrentView(view);
'}
End Sub
''' <summary>
''' 根据图形边界显示视图
''' </summary>
''' <param name="ed"></param>
<System.Runtime.CompilerServices.Extension> _
Public Shared Sub ZoomExtens(ed As Editor)
acadApplication.ZoomExtents()
'Database db = ed.Document.Database;
'db.UpdateExt(true);
Dim 根据当前图形的界限范围对视图进行缩放 As 更新当前模型空间的范围
'if (db.Extmax.X < db.Extmin.X)
'{
' Plane plane = new Plane();
' Point3d pt1 = new Point3d(plane, db.Limmin);
' Point3d pt2 = new Point3d(plane, db.Limmax);
' ed.ZoomWindow(pt1, pt2);
'}
'else
'{
' ed.ZoomWindow(db.Extmin, db.Extmax);
'}
End Sub
''' <summary>
''' 根据对象的范围显示视图
''' </summary>
''' <param name="editor"></param>
''' <param name="objectId">实体ID</param>
<System.Runtime.CompilerServices.Extension> _
Public Shared Sub ZoomObject(editor As Editor, objectId As ObjectId)
Dim db As Database = editor.Document.Database
Using trans As Transaction = db.TransactionManager.StartTransaction()
'获取实体对象
Dim entity As Entity = TryCast(trans.GetObject(objectId, OpenMode.ForRead), Entity)
If entity Is Nothing Then
Return
End If
'根据实体的范围对视图进行缩放
Dim extents3 As Extents3d = entity.GeomExtents
extents3.TransformBy(editor.CurrentUserCoordinateSystem.Inverse())
editor.ZoomWindow(extents3.MinPoint, extents3.MaxPoint)
trans.Commit()
End Using
End Sub
End Class
End Namespace
Acad.Invoke
欢迎关注微信公众账号ByCAD