田草博客

互联网田草博客


网友交流QQ群:11740834 需注明申请加入原因

微信 公众号:ByCAD

邮箱:tiancao1001x126.com
ByCAD,微信公众号
首页 | 普通 | 电脑 | AutoCAD | VB/VB.NET | FLash | 结构 | 建筑 | 电影 | BIM | 规范 | 软件 | ID
-随机-|-分布-
-博客论坛-|-﨣﨤﨧﨨-
-网站导航-|-规范下载-
-BelovedFLash欣赏-

用户登陆
用户:
密码:
 

站点日历
73 2024 - 3 48
     12
3456789
10111213141516
17181920212223
24252627282930
31


站点统计

最新评论



Acad.Invoke CommandMethod
未知 视图操作类,缩放   [ 日期:2021-11-14 ]   [ 来自:本站原创 ]  HTML
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



暂时没有评论
发表评论 - 不要忘了输入验证码哦!
作者: 用户:  密码:   注册? 验证:  防止恶意留言请输入问题答案:2*3=?  
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字

字体样式 文字大小 文字颜色
插入粗体文本 插入斜体文本 插入下划线
左对齐 居中对齐 右对齐
插入超级链接 插入邮件地址 插入图像
插入 Flash 插入代码 插入引用
插入列表 插入音频文件 插入视频文件
插入缩进符合
点击下载按钮 下标 上标
水平线 简介分割标记
表  情
 
Tiancao Blog All Rights Reserved 田草博客 版权所有
Copyright ©