使用C#模拟AutoCAD视图的行为

我有一个从AutoCAD程序中用AutoCAD绘制的对象.绘制对象后,我将相机设置为从顶视图向下俯视墙.我当时想要它做的是向前视图向下45度,向左视图向左45度.这基本上模仿了在AutoCAD中选择对象,然后单击视图立方体.

enter image description here

这是我的轨道方法.

/// <summary>
/// Orbit the angle around a passed axis
/// </summary>
public static void Orbit(Vector3d axis,Point3d pivotPoint,Angle angle)
{
    Editor activeEditor = AcadApp.DocumentManager.MdiActiveDocument.Editor; //Get editor for current document
    ViewTableRecord activeView = activeEditor.GetCurrentView(); //Get current view table
    activeView.ViewDirection = activeView.ViewDirection.TransformBy(Matrix3d.Rotation(angle.radians,axis,pivotPoint)); //Adjust the ViewTableRecord
    activeEditor.SetCurrentView(activeView); //Set it as the current view
}

这就是我如何调用轨道方法

CameraMethods.Orbit(Vector3d.XAxis,GeometryAdapter.ClearspanPointToAcadPoint(wallToZoomTo.FrontLine.MidPoint),new Angle(AngleType.Radian,Math.PI / 4));
CameraMethods.Orbit(Vector3d.ZAxis,Math.PI / 4));

问题是,当我进入墙体物体的中点时,它会绕着相机运行,使它离得很远(在视图左上方的某处)

有没有人有办法通过C#轻松绕过AutoCAD中选定的对象?提前致谢!

解决方法

试试这个:

[CommandMethod("MYORBIT")]
public void MyOrbit()
{
  Document doc = Application.DocumentManager.MdiActiveDocument;
  Database db = doc.Database;
  Editor ed = doc.Editor;

  PromptPointResult ppr = ed.GetPoint("\nSelect orbit point: ");
  if (ppr.Status == PromptStatus.Cancel) return;

  using (Transaction tr = db.TransactionManager.StartTransaction())
  {
    short cvport = (short)Application.GetSystemVariable("CVPORT");
    using (Manager gm = doc.GraphicsManager)
    using (var kd = new KernelDescriptor())
    {
      kd.addRequirement(Autodesk.AutoCAD.UniqueString.Intern("3D Drawing"));
      using (View view = gm.ObtainAcGsView(cvport,kd))
      {
        double d = view.Position.distanceto(view.Target);
        view.SetView(ppr.Value + new Vector3d(-1,-1,1).Getnormal() * d,ppr.Value,Vector3d.ZAxis,view.FieldWidth,view.FieldHeight);
        gm.SetViewportFromView(cvport,view,true,true);
      }
    }

    // Needed if wireframe 2D
    ed.Regen();

    tr.Commit();
  }
}

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...