Imagine the behavior of an AutoCAD Cup with C #

I have an object that I draw in AutoCAD from my program. After the object is drawn, I have a camera installed, so that it scales to the wall, looking down from the top view. What I want to do then is turn 45 degrees down towards the front and 45 degrees left to left. This essentially simulates the selection of an object in AutoCAD, and then click the view cube.

enter image description here

Here is my orbit method.

/// <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 } 

And this is what I call the orbit method

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

The problem is that when I go to the middle of the wall object, it rotates the camera so that it is very far away (at the top, top left of the review somewhere)

Does anyone have the ability to easily navigate around a selected object in AutoCAD through C #? Thanks in advance!

+4
source share
1 answer

Try the following:

 [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, true); } } // Needed if wireframe 2D ed.Regen(); tr.Commit(); } } 
0
source

All Articles