Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VB Get the angle in degree of the Y axis in my current view

1 REPLY 1
Reply
Message 1 of 2
peter.stahl
492 Views, 1 Reply

VB Get the angle in degree of the Y axis in my current view

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.

 

 yGKSonDxEM.png

 

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

 

Labels (1)
1 REPLY 1
Message 2 of 2
_dscholtes_
in reply to: peter.stahl

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)

 

  1. The direction of the Y-axis can be obtain with something like:
    oVectorY = <your open file>.ComponentDefinition.WorkAxes(2).Line.Direction.AsVector
  2. You have to convert it to a UnitVector, like:
    oVectorUp = oVectorY.AsUnitVector
  3. Set it to the camera object:
    oCamera.UpVector = oVectorUp
  4. And apply settings:
    oCamera.Apply

 

If you do want to calculate the angle, I'd try the following:

  1. Get the UpVector of the camera and store it as a vector (oVector1);
  2. Store the direction of the Y-axis as a vector (oVector2);
  3. Calculate the angle between them using: dAngle = oVector1.AngleTo(oVector2), where dAngle is a double.
    (I don't know which angle between the vectors is returned, the large or the small one)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report