Camera Traversal in AutoCAD 2015 with C #

I am writing a static class that contains methods to make it easier to work with an AutoCAD camera. All of my methods seem to work except for orbit. Heres my orbit method in the context of my class

public static class CameraMethods
    {
        #region _variables and Properties
        private static Document _activeDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
        private static Database _database = _activeDocument.Database;
        private static Editor _editor = _activeDocument.Editor;
        private static ViewTableRecord _initialView = _editor.GetCurrentView();
        private static ViewTableRecord _activeViewTableRecord = (ViewTableRecord)_initialView.Clone();
        #endregion

/// <summary>
        /// Orbit the angle around a passed axis
        /// </summary>
        public static void Orbit(Vector3d axis, Angle angle)
        {
            // Adjust the ViewTableRecord
            //var oldDirection = _activeViewTableRecord.ViewDirection;
            _activeViewTableRecord.ViewDirection = _activeViewTableRecord.ViewDirection.TransformBy(Matrix3d.Rotation(angle.Radians, axis, Point3d.Origin));

            // Set it as the current view
            _editor.SetCurrentView(_activeViewTableRecord);
        }
}

      

The problem is that every time I call the orbit, the orbits are based on the representation from the previous time I rotated. For example, the first time I call the orbit to orbit 45 degrees around the x-axis, it does what I expect. However, if I change the camera inside the autoframe, then call this method again, it rotates as if I called it twice; 90 degrees in X axis. I need some advice on how to fix this.

+3


source to share


1 answer


Since the active document can change in AutoCAD (this is an MDI application), I would not recommend storing these objects as STATIC as you do.



Instead, every call that depends on MdiActiveDocument should get all of these variables on every command call. This may be the reason why you are getting this behavior.

+1


source







All Articles