CAD.NET 缩放窗口\设置窗口大小

本文介绍了使用CAD.NET进行窗口缩放和设置窗口大小的操作方法,通过ViewTableRecord和AbstractViewTableRecord等技术实现对CAD界面的精细化控制。

CAD.NET 缩放窗口

using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Runtime;
using System;

namespace Autodesk.AutoCAD.DatabaseServices
{
    [Wrapper("AcDbAbstractViewTableRecord")]
    public abstract class AbstractViewTableRecord : SymbolTableRecord
    {
        protected internal AbstractViewTableRecord(IntPtr obj, bool autoDelete);

        public Color AmbientLightColor { get; set; }
        [UnitType(UnitType.Distance)]
        public double BackClipDistance { get; set; }
        public bool BackClipEnabled { get; set; }
        public ObjectId Background { get; set; }
        [UnitType(UnitType.Unitless)]
        public double Brightness { get; set; }
        public Point2d CenterPoint { get; set; }
        [UnitType(UnitType.Unitless)]
        public double Contrast { get; set; }
        public bool DefaultLightingOn { get; set; }
        public DefaultLightingType DefaultLightingType { get; set; }
        [UnitType(UnitType.Distance)]
        public double Elevation { get; set; }
        public bool FrontClipAtEye { get; set; }
        [UnitType(UnitType.Distance)]
        public double FrontClipDistance { get; set; }
        public bool FrontClipEnabled { get; set; }
        [UnitType(UnitType.Distance)]
        public double Height { get; set; }
        [UnitType(UnitType.Distance)]
        public double LensLength { get; set; }
        public bool PerspectiveEnabled { get; set; }
        public ObjectId SunId { get; }
        public Point3d Target { get; set; }
        public ToneOperatorParameters ToneOperatorParameters { get; set; }
        public CoordinateSystem3d Ucs { get; }
        public ObjectId UcsName { get; }
        public OrthographicView UcsOrthographic { get; }
        public Vector3d ViewDirection { get; set; }
        public OrthographicView ViewOrthographic { get; }
        [UnitType(UnitType.Angle)]
        public double ViewTwist { get; set; }
        public ObjectId VisualStyleId { get; set; }
        [UnitType(UnitType.Distance)]
        public double Width { get; set; }

        public ObjectId SetSun(DBObject sun);
        public void SetUcs(ObjectId id);
        public void SetUcs(OrthographicView view);
        public void SetUcs(Point3d origin, Vector3d x, Vector3d y);
        public void SetUcsToWorld();
        public void SetViewDirection(OrthographicView view);
    }
}
using Autodesk.AutoCAD.Runtime;
using System;
using System.Xml.Serialization;

namespace Autodesk.AutoCAD.DatabaseServices
{
    [Wrapper("AcDbViewTableRecord")]
    public class ViewTableRecord : AbstractViewTableRecord
    {
        public ViewTableRecord();
        protected internal ViewTableRecord(IntPtr obj, bool autoDelete);

        public AnnotationScale AnnotationScale { get; set; }
        public string CategoryName { get; set; }
        public bool IsPaperspaceView { get; set; }
        public bool IsUcsAssociatedToView { get; }
        public string LayerState { get; set; }
        public ObjectId Layout { get; set; }
        public ObjectId LiveSection { get; set; }
        [XmlIgnore]
        public System.Drawing.Bitmap Thumbnail { get; set; }
        public bool ViewAssociatedToViewport { get; set; }

        public void DisassociateUcsFromView();
    }
}
/// <summary>
/// 设置窗口大小
/// </summary>
/// <param name="ptMin"></param>
/// <param name="ptMax"></param>
/// <param name="scale">图形窗口大小将被设置为指定大小的scale倍</param>
public static void Set(Point3d ptMin, Point3d ptMax, double scale)
{
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    ViewTableRecord view = ed.GetCurrentView();
    view.Height = (Math.Abs(ptMax.Y - ptMin.Y) * scale);
    view.Width = (Math.Abs(ptMax.X - ptMin.X) * scale);
    view.CenterPoint = new Point2d((ptMax.X + ptMin.X) / 2, (ptMax.Y + ptMin.Y) / 2);
    //设为当前视图
    ed.SetCurrentView(view);
    Application.UpdateScreen();
}

一切皆有可能,不是吗?时间会给你答案!

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值