微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用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();
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐