我有一个从AutoCAD程序中用AutoCAD绘制的对象.绘制对象后,我将相机设置为从顶视图向下俯视墙.我当时想要它做的是向前视图向下45度,向左视图向左45度.这基本上模仿了在AutoCAD中选择对象,然后单击视图立方体.
这是我的轨道方法.
/// <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(); } }