一直有关于Zoom的问题,虽然在手册中有相应的代码,但并不能解决实际问题
下面是段在模型空间中Zoom的函数
要求VS版本2008
调用方法
先
- using TlsCad.ExtendMethods;
然后复制代码
-
-
- using System;
- using System.Collections.Generic;
- using Autodesk..ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.Runtime;
- using TlsCad.Collections;
- namespace TlsCad.ExtendMethods
- {
- public enum CoordinateSystemCode
- {
- Wcs = 0,
- Ucs,
- MDcs,
- PDcs
- }
- public static class EditorEx
- {
- #region Matrix
- ///
- /// 获取UCS到WCS的矩阵
- ///
- ///
- ///
- public static Matrix3d GetMatrixFromUcsToWcs(this Editor editor)
- {
- return editor.CurrentUserCoordinateSystem;
- }
- ///
- /// 获取WCS到UCS的矩阵
- ///
- ///
- ///
- public static Matrix3d GetMatrixFromWcsToUcs(this Editor editor)
- {
- return editor.CurrentUserCoordinateSystem.Inverse();
- }
- ///
- /// 获取MDCS(模型空间)到WCS的矩阵
- ///
- ///
- ///
- public static Matrix3d GetMatrixFromMDcsToWcs(this Editor editor)
- {
- Matrix3d mat;
- using (ViewTableRecord vtr = editor.GetCurrentView())
- {
- mat = Matrix3d.PlaneToWorld(vtr.ViewDirection);
- mat = Matrix3d.Displacement(vtr.Target - Point3d.Origin) * mat;
- return Matrix3d.Rotation(-vtr.ViewTwist, vtr.ViewDirection, vtr.Target) * mat;
- }
- }
- ///
- /// 获取WCS到MDCS(模型空间)的矩阵
- ///
- ///
- ///
- public static Matrix3d GetMatrixFromWcsToMDcs(this Editor editor)
- {
- return editor.GetMatrixFromMDcsToWcs().Inverse();
- }
- ///
- /// 获取MDCS(模型空间)到PDCS(图纸空间)的矩阵
- ///
- ///
- ///
- public static Matrix3d GetMatrixFromMDcsToPDcs(this Editor editor)
- {
- if ((short)Application.GetSystemVariable("TILEMODE") == 1)
- throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.InvalidInput, "Espace papier uniquement");
- Database db = editor.Document.Database;
- Matrix3d mat;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- Viewport vp =
- (Viewport)tr.GetObject(editor.CurrentViewportObjectId, OpenMode.ForRead);
- if (vp.Number == 1)
- {
- try
- {
- editor.SwitchToModelSpace();
- vp = (Viewport)tr.GetObject(editor.CurrentViewportObjectId, OpenMode.ForRead);
- editor.SwitchToPaperSpace();
- }
- catch
- {
- throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.InvalidInput, "Aucun fenêtre active");
- }
- }
- Point3d vCtr = new Point3d(vp.ViewCenter.X, vp.ViewCenter.Y, 0.0);
- mat = Matrix3d.Displacement(vCtr.GetAsVector().Negate());
- mat = Matrix3d.Displacement(vp.CenterPoint.GetAsVector()) * mat;
- mat = Matrix3d.Scaling(vp.CustomScale, vp.CenterPoint) * mat;
- tr.Commit();
- }
- return mat;
- }
- ///
- /// 获取PDCS(图纸空间)到MDCS(模型空间)的矩阵
- ///
- ///
- ///
- public static Matrix3d GetMatrixFromPDcsToMDcs(this Editor editor)
- {
- return editor.GetMatrixFromMDcsToPDcs().Inverse();
- }
- public static Matrix3d GetMatrix(this Editor editor, CoordinateSystemCode from, CoordinateSystemCode to)
- {
- switch (from)
- {
- case CoordinateSystemCode.Wcs:
- switch (to)
- {
|