<?xml encoding=”UTF-8″>By Adam Nagy
This is a generalization of this post:
http://adndevblog.typepad.com/manufacturing/2014/11/rotate-drawing-view-around-x-axis-of-sheet.html
Here we’ll use the Matrix class to help us create a matrix that can transform any point or vector around any vector/axis and an angle: Matrix.SetToRotation(Angle As Double, Axis As Vector, Center As Point)
To make sure we have a precise radian value for 90 degrees I’m using 2 * Atn(1) inside VBA. In languages like .NET there is a constant for PI, so you could use that instead.
We just need to get the vector we want to rotate around inside the Model space. If the vector we want to use is in the Sheet space then we need to transform it using SheetToModelTransform matrix.
Once we have both the rotation centre (Camera.Target in our case) and the rotation axis (Sheet X inside the model space in our case) then we can create the transformation matrix and use it to get the new Eye position and UpVector direction.
Sub RotateBaseView()
Dim baseView As DrawingView
Set baseView = ThisApplication.ActiveDocument.SelectSet(1)
Dim tr As TransientGeometry
Set tr = ThisApplication.TransientGeometry
Dim c As Camera
Set c = baseView.Camera
Dim oldEye As Point
Set oldEye = c.eye.Copy
Dim oldTarget As Point
Set oldTarget = c.Target.Copy
Dim oldUpVector As UnitVector
Set oldUpVector = c.UpVector.Copy
' Get the Sheet's X axis into the model space
Dim sheetXInModel As Vector
Set sheetXInModel = tr.CreateVector(1, 0, 0)
Call sheetXInModel.TransformBy(baseView.SheetToModelTransform)
' Calculate rotation in the model
' around the Target and the Sheet X
' in model space
Dim m As Matrix
Set m = tr.CreateMatrix()
' Set the rotation angle to 90 degrees
' Atn(1) = 45 degrees in radian
Dim Rad90 As Double
Rad90 = 2 * Math.Atn(1)
Call m.SetToRotation(Rad90, sheetXInModel, oldTarget)
' Now we just have to transform the points and
' vectors
Call oldEye.TransformBy(m)
c.eye = oldEye
Call oldUpVector.TransformBy(m)
c.UpVector = oldUpVector
Call c.ApplyWithoutTransition
End Sub

Leave a Reply