Hey guys,
it's a bit complicated to explain WHY - but I need to get the angle of the Y axis in the current view. The picture helps to explain what I need.
I have put together a code to turn the screen around the axis that stands vertical on my screendisplay (not the UCS axis!).
If I would be able to measure how many degree the Y axis in my current view is off, let's say 5°, than I can rotate the view -5° back with my function below.
Do you have any idea how to measure the angle?
Public Sub RotateMe()
Call RotateAroundDisplayAxis("Z", -5)
End Sub
Public Sub RotateAroundDisplayAxis(ByVal axis As String, ByVal degree As Integer, Optional ByVal CW As Boolean = True)
' collected by PS 2020.10.05
' This example simply rotates the view around an axis of the actual view - not the UCS!
' turning around the axis vertical to the screen from: http://ww3.cad.de/foren/ubb/Forum258/HTML/000587.shtml
' turning around the vertical & horizontal axis of the screen from: https://forums.autodesk.com/t5/inventor-customization/camera-upvector/td-p/757637
Dim oView As View
Set oView = ThisApplication.ActiveView
Dim oCamera As camera
Set oCamera = oView.camera
Select Case axis
Case "Z"
Dim uVector As UnitVector
ox = oCamera.Eye.x - oCamera.Target.x
oy = oCamera.Eye.y - oCamera.Target.y
oz = oCamera.Eye.Z - oCamera.Target.Z
Set oNewUp = ThisApplication.TransientGeometry.CreateUnitVector(ox, oy, oz)
If CW Then 'rotate CW
oCamera.UpVector = oNewUp.CrossProduct(oCamera.UpVector)
Else 'rotate CCW
oCamera.UpVector = oCamera.UpVector.CrossProduct(oNewUp)
End If
Case "X", "Y"
Dim FPoint As Point2d 'rotation points
Dim TPoint As Point2d
Dim rVal As Double 'rotation values
Dim yVal As Double
Dim radV As Double
radV = Math.Atn(1) / 2.25 'PS: Math.Atn(1) = 45°
rVal = degree * -radV
If CW Then 'rotate CW
Select Case axis
Case "X"
Set FPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
Set TPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, rVal)
Case "Y"
Set FPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
Set TPoint = ThisApplication.TransientGeometry.CreatePoint2d(rVal, 0)
End Select
Else 'rotate CCW
Select Case axis
Case "X"
Set FPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, rVal)
Set TPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
Case "Y"
Set FPoint = ThisApplication.TransientGeometry.CreatePoint2d(rVal, 0)
Set TPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
End Select
End If
oCamera.ComputeWithMouseInput FPoint, TPoint, 0, kRotateViewOperation
End Select
oCamera.Apply
oCamera.Fit
End Sub
If you only want to rotate the screen such that the Y-axis is aligned vertical (and points up), I would store the direction of the Y-axis in a vector and set it as the UpVector of the camera object. After that, just Apply the new settings (without need for any calculations)
If you do want to calculate the angle, I'd try the following:
Can't find what you're looking for? Ask the community or share your knowledge.