首页 > 其他分享 >CAD.net Zoom

CAD.net Zoom

时间:2022-11-02 17:01:12浏览次数:56  
标签:ed Zoom ext static new using net CAD view

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace Autodesk.AutoCAD.EditorInput
{
    public static class ExtensionMethods
    {
        public static Matrix3d EyeToWorld(this ViewTableRecord view)
        {
            if (view == null)
                throw new ArgumentNullException("view");
 
            return
                Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) *
                Matrix3d.Displacement(view.Target - Point3d.Origin) *
                Matrix3d.PlaneToWorld(view.ViewDirection);
        }
 
        public static Matrix3d WorldToEye(this ViewTableRecord view)
        {
            return view.EyeToWorld().Inverse();
        }
 
        public static void Zoom(this Editor ed, Extents3d ext)
        {
            if (ed == null)
                throw new ArgumentNullException("ed");
 
            using (ViewTableRecord view = ed.GetCurrentView())
            {
                ext.TransformBy(view.WorldToEye());
                view.Width = ext.MaxPoint.X - ext.MinPoint.X;
                view.Height = ext.MaxPoint.Y - ext.MinPoint.Y;
                view.CenterPoint = new Point2d(
                    (ext.MaxPoint.X + ext.MinPoint.X) / 2.0,
                    (ext.MaxPoint.Y + ext.MinPoint.Y) / 2.0);
                ed.SetCurrentView(view);
            }
        }
 
        public static void ZoomCenter(this Editor ed, Point3d center, double scale = 1.0)
        {
            if (ed == null)
                throw new ArgumentNullException("ed");
 
            using (ViewTableRecord view = ed.GetCurrentView())
            {
                center = center.TransformBy(view.WorldToEye());
                view.Height /= scale;
                view.Width /= scale;
                view.CenterPoint = new Point2d(center.X, center.Y);
                ed.SetCurrentView(view);
            }
        }
 
        public static void ZoomExtents(this Editor ed)
        {
            if (ed == null)
                throw new ArgumentNullException("ed");
 
            Database db = ed.Document.Database;
            db.UpdateExt(false);
            Extents3d ext = (short)Application.GetSystemVariable("cvport") == 1 ?
                new Extents3d(db.Pextmin, db.Pextmax) :
                new Extents3d(db.Extmin, db.Extmax);
            ed.Zoom(ext);
        }
 
        public static void ZoomObjects(this Editor ed, IEnumerable<ObjectId> ids)
        {
            if (ed == null)
                throw new ArgumentNullException("ed");
 
            using (Transaction tr = ed.Document.TransactionManager.StartTransaction())
            {
                Extents3d ext = ids
                    .Where(id => id.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Entity))))
                    .Select(id => ((Entity)tr.GetObject(id, OpenMode.ForRead)).GeometricExtents)
                    .Aggregate((e1, e2) => { e1.AddExtents(e2); return e1; });
                ed.Zoom(ext);
                tr.Commit();
            }
        }
 
        public static void ZoomScale(this Editor ed, double scale)
        {
            if (ed == null)
                throw new ArgumentNullException("ed");
 
            using (ViewTableRecord view = ed.GetCurrentView())
            {
                view.Width /= scale;
                view.Height /= scale;
                ed.SetCurrentView(view);
            }
        }
 
        public static void ZoomWindow(this Editor ed, Point3d p1, Point3d p2)
        {
            using (Line line = new Line(p1, p2))
            {
                ed.Zoom(line.GeometricExtents);
            }
        }
    }
}

 

标签:ed,Zoom,ext,static,new,using,net,CAD,view
From: https://www.cnblogs.com/gudebai/p/16851580.html

相关文章

  • SEVGGNET-LSTM: A FUSED DEEP LEARNING MODEL FOR ECG CLASSIFICATION
    https://arxiv.org/pdf/2210.17111.pdf------------------------------------------------------------------------------2022-11-21.数据标准化:均值、方差为数据集的......
  • .Net Core验证码
    1、复制下列代码,拷贝到控制器中。#region生成验证码图片//[OutputCache(Location=OutputCacheLocation.None,Duration=0,NoStore=false)]......
  • C# .net ERP SAP 通过传表进行查询
    RfcDestinationdest=rfc_public.GetRfcDestination("SMP");IRfcFunctionfunc=dest.Repository.CreateFunction("ZPP_SYHD_GET_ISSUE_CHARGE");//接......
  • kubernetes的yml
    kubernetes的yml1:创建namespace文件po.yml内容如下apiVersion:v1kind:Namespacemetadata:name:po 命令:kubectlapply-fpo.yml 删除namespace......
  • Net6开原框架Furion
    十年河东,十年河西,莫欺少年穷我入驻博客园十年了,十年来,让我从一个青春小伙变成了秃头大佬,呵呵今天一同事推荐了一个框架,在此记录下:参考地址:https://furion.baiqian.ltd/d......
  • 深入浅出ASP .NET Core学习记录
    深入浅出ASP.NETCore学习记录《深入浅出》第二部分总结第二章的学习代码:代码概括主要是实操,下面是实操完的项目结构图几个文件夹,代表什么意思Controllers(重......
  • AutoCAD 数据库入门
    1.AutoCAD数据库概述AutoCAD图形是存储在数据库中的对象集合。一些基本的数据库对象是实体、符号表和字典。实体是一种特殊的数据库对象,在AutoCAD图形中具有图形表示......
  • 关于 NGINX Kubernetes Gateway,你需要知道的 5 件事
    原文作者:IlyaKrutovofF5原文链接:​​​关于NGINXKubernetesGateway,你需要知道的5件事​​转载来源:NGINX官方网站在过去的几年里,F5NGINX帮助您成功走完了Kuberne......
  • .Net Core后台任务启停(BackgroundService)
    BackgroundService描述说明:BackgroundService类 说到定时任务,可能第一个会想到Quartz,但是想到需要更简洁,而且想要毫秒级的周期,这个Cron真是太不智慧了,虽说可以在单个......
  • ubuntu 22.04 编译NetBSD
    本文参考链接:https://www.its301.com/article/u013257164/107532121偶然看到NetBSD源码可以在其他平台(linux,FreeBSD)上编译,亲自在ubuntu22.04试验了一下,确实可以,加......