明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3454|回复: 1

使用Autodesk.AutoCAD.GraphicsSystem.View类,文档却没有反应,怎么回事。例如:

[复制链接]
发表于 2009-8-28 17:11 | 显示全部楼层 |阅读模式
            Autodesk.AutoCAD.GraphicsSystem.View zoom = new Autodesk.AutoCAD.GraphicsSystem.View();
            zoom.Zoom(2);
没反应。
发表于 2009-8-28 17:26 | 显示全部楼层
GraphicsSystem->图形接口,使用不是这样简单的
你只是新建一个View对象还不够,必须把它和当前视图联系起来
View可以用来Zoom,但操作无法回退
看过手册里的例子么?
建议你先按下心来仔细看下资料
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.DatabaseServices;
  3. using Autodesk.AutoCAD.Runtime;
  4. using Autodesk.AutoCAD.Geometry;
  5.   
  6. static void Zoom(Point3d pMin, Point3d pMax, Point3d pCenter, double dFactor)
  7. {
  8.   // Get the current document and database
  9.   Document acDoc = Application.DocumentManager.MdiActiveDocument;
  10.   Database acCurDb = acDoc.Database;
  11.   
  12.   int nCurVport = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));
  13.   
  14.   // Get the extents of the current space no points
  15.   // or only a center point is provided
  16.   // Check to see if Model space is current
  17.   if (acCurDb.TileMode == true)
  18.   {
  19.       if (pMin.Equals(new Point3d()) == true &&
  20.           pMax.Equals(new Point3d()) == true)
  21.       {
  22.           pMin = acCurDb.Extmin;
  23.           pMax = acCurDb.Extmax;
  24.       }
  25.   }
  26.   else
  27.   {
  28.       // Check to see if Paper space is current
  29.       if (nCurVport == 1)
  30.       {
  31.           // Get the extents of Paper space
  32.           if (pMin.Equals(new Point3d()) == true &&
  33.               pMax.Equals(new Point3d()) == true)
  34.           {
  35.               pMin = acCurDb.Pextmin;
  36.               pMax = acCurDb.Pextmax;
  37.           }
  38.       }
  39.       else
  40.       {
  41.           // Get the extents of Model space
  42.           if (pMin.Equals(new Point3d()) == true &&
  43.               pMax.Equals(new Point3d()) == true)
  44.           {
  45.               pMin = acCurDb.Extmin;
  46.               pMax = acCurDb.Extmax;
  47.           }
  48.       }
  49.   }
  50.   
  51.   // Start a transaction
  52.   using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  53.   {
  54.       // Get the current view
  55.       using (ViewTableRecord acView = acDoc.Editor.GetCurrentView())
  56.       {
  57.           Extents3d eExtents;
  58.   
  59.           // Translate WCS coordinates to DCS
  60.           Matrix3d matWCS2DCS;
  61.           matWCS2DCS = Matrix3d.PlaneToWorld(acView.ViewDirection);
  62.           matWCS2DCS = Matrix3d.Displacement(acView.Target - Point3d.Origin) * matWCS2DCS;
  63.           matWCS2DCS = Matrix3d.Rotation(-acView.ViewTwist,
  64.                                          acView.ViewDirection,
  65.                                          acView.Target) * matWCS2DCS;
  66.   
  67.           // If a center point is specified, define the min and max
  68.           // point of the extents
  69.           // for Center and Scale modes
  70.           if (pCenter.DistanceTo(Point3d.Origin) != 0)
  71.           {
  72.               pMin = new Point3d(pCenter.X - (acView.Width / 2),
  73.                                  pCenter.Y - (acView.Height / 2), 0);
  74.   
  75.               pMax = new Point3d((acView.Width / 2) + pCenter.X,
  76.                                  (acView.Height / 2) + pCenter.Y, 0);
  77.           }
  78.   
  79.           // Create an extents object using a line
  80.           using (Line acLine = new Line(pMin, pMax))
  81.           {
  82.               eExtents = new Extents3d(acLine.Bounds.Value.MinPoint,
  83.                                        acLine.Bounds.Value.MaxPoint);
  84.           }
  85.   
  86.           // Calculate the ratio between the width and height of the current view
  87.           double dViewRatio;
  88.           dViewRatio = (acView.Width / acView.Height);
  89.   
  90.           // Tranform the extents of the view
  91.           matWCS2DCS = matWCS2DCS.Inverse();
  92.           eExtents.TransformBy(matWCS2DCS);
  93.   
  94.           double dWidth;
  95.           double dHeight;
  96.           Point2d pNewCentPt;
  97.   
  98.           // Check to see if a center point was provided (Center and Scale modes)
  99.           if (pCenter.DistanceTo(Point3d.Origin) != 0)
  100.           {
  101.               dWidth = acView.Width;
  102.               dHeight = acView.Height;
  103.   
  104.               if (dFactor == 0)
  105.               {
  106.                   pCenter = pCenter.TransformBy(matWCS2DCS);
  107.               }
  108.   
  109.               pNewCentPt = new Point2d(pCenter.X, pCenter.Y);
  110.           }
  111.           else // Working in Window, Extents and Limits mode
  112.           {
  113.               // Calculate the new width and height of the current view
  114.               dWidth = eExtents.MaxPoint.X - eExtents.MinPoint.X;
  115.               dHeight = eExtents.MaxPoint.Y - eExtents.MinPoint.Y;
  116.   
  117.               // Get the center of the view
  118.               pNewCentPt = new Point2d(((eExtents.MaxPoint.X + eExtents.MinPoint.X) * 0.5),
  119.                                        ((eExtents.MaxPoint.Y + eExtents.MinPoint.Y) * 0.5));
  120.           }
  121.   
  122.           // Check to see if the new width fits in current window
  123.           if (dWidth > (dHeight * dViewRatio)) dHeight = dWidth / dViewRatio;
  124.   
  125.           // Resize and scale the view
  126.           if (dFactor != 0)
  127.           {
  128.               acView.Height = dHeight * dFactor;
  129.               acView.Width = dWidth * dFactor;
  130.           }
  131.   
  132.           // Set the center of the view
  133.           acView.CenterPoint = pNewCentPt;
  134.   
  135.           // Set the current view
  136.           acDoc.Editor.SetCurrentView(acView);
  137.       }
  138.   
  139.       // Commit the changes
  140.       acTrans.Commit();
  141.   }
  142. }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-14 03:39 , Processed in 0.131993 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表