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: 

Turn Inventor camera in assemblyview 30 degrees

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
juliengoertz
207 Views, 2 Replies

Turn Inventor camera in assemblyview 30 degrees

I am looking for a piece of (iLogic, VB, c#) code that can rotate the camera in the Assemblyview 30 degrees over the vertical Z-axis. Clock-wise or counter-clockwise. I don't need a transition because i need it to take screenshots of tons of products. I have found multiple pieces of code that can turn the camera, but as far as i am seeing none that have the amount of degrees turned as a input parameter. Or in which you can chose the direction in which to turn. For example: 

Sub Main()
RotateCamMacro()	
End Sub


Public Sub RotateCamMacro()
 
    Dim pi As Double
    pi = Math.PI
    
    'Rotation speed in Rad/Sec
    Dim rotSpeedRad As Double
    rotSpeedRad = 40 * pi / 180
    
    'Get part document
    Dim doc As Document
    doc = ThisApplication.ActiveDocument
    
    'Get range box center point
    Dim centerPoint As Point
    centerPoint = GetRangeBoxCenter(doc)
    
    'Set camera orientation
    Call SetCameraOrientation( _
        centerPoint, _
        ViewOrientationTypeEnum.kIsoTopRightViewOrientation)
    
    'Get Inventor camera
    Dim camera As Inventor.Camera
    camera = ThisApplication.ActiveView.Camera
    
    Dim totalRot As Double
    totalRot = 0
    
    Dim offsetRad As Double
    
    Dim rotAxis As Vector
    rotAxis = ThisApplication.TransientGeometry.CreateVector(1, 0, 0)
    
    Dim upVector As UnitVector
    upVector = ThisApplication.TransientGeometry.CreateUnitVector(0, 1, 0)
    
    Do While (totalRot < 2 * pi)
    
        offsetRad = 0.05 * rotSpeedRad
        
        RotateCam(camera, offsetRad, rotAxis, centerPoint, upVector)
        
        totalRot = totalRot + offsetRad
        
    Loop
    
    Call SetCameraOrientation( _
        centerPoint, _
        ViewOrientationTypeEnum.kIsoTopRightViewOrientation)
    
End Sub

Public Function GetRangeBoxCenter(ByVal doc As Document) As Point

    Dim minPoint As Point
    minPoint = doc.ComponentDefinition.RangeBox.minPoint
    
    Dim maxPoint As Point
    maxPoint = doc.ComponentDefinition.RangeBox.maxPoint
    
    GetRangeBoxCenter = ThisApplication.TransientGeometry.CreatePoint( _
        (minPoint.X + maxPoint.X) * 0.5, _
        (minPoint.Y + maxPoint.Y) * 0.5, _
        (minPoint.Z + maxPoint.Z) * 0.5)

End Function

Public Sub SetCameraOrientation( _
    ByVal targetPoint As Point, _
    ByVal viewOrientation As ViewOrientationTypeEnum)

    Dim camera As Inventor.Camera
    camera = ThisApplication.ActiveView.Camera
    
    camera.ViewOrientationType = viewOrientation
    camera.Target = targetPoint
    
    Call camera.Fit
    Call camera.ApplyWithoutTransition

End Sub

Public Sub RotateCam( _
    camera As Camera, _
    ByVal offsetRad As Double, _
    rotAxis As Vector, _
    center As Point, _
    upVector As UnitVector)

    Dim matrix As Matrix
    matrix = ThisApplication.TransientGeometry.CreateMatrix
    
    Call matrix.SetToRotation(offsetRad, rotAxis, center)
    
    Dim newEye As Point
    newEye = camera.Eye
    
    Call newEye.TransformBy(matrix)
    
    camera.Eye = newEye
    
    camera.UpVector = upVector
    
    Call camera.ApplyWithoutTransition
    
End Sub

Thank you guys in advance. I have been trying for a couple of days

2 REPLIES 2
Message 2 of 3

This is an iLogic sample how to rotate camera around Z axis. 

Sub Main()

    'Get camera of active view 
    Dim activeView As Inventor.View = ThisApplication.ActiveView
    dim cam As Camera = activeView.Camera 

    'Get current vector from target to eye
    Dim vectorToEye as Vector = cam.Target.VectorTo(cam.Eye)

    'Define rotation matrix for 30 deg around Z axis
    Dim angle As Double = PI/6
    Dim zAxis As Vector = ThisApplication.TransientGeometry.CreateVector(0,0,1)
    Dim origin As Point = ThisApplication.TransientGeometry.CreatePoint(0,0,0)
    Dim rotationMtx As Matrix = ThisApplication.TransientGeometry.CreateMatrix()
    rotationMtx.SetToRotation(angle, zAxis, origin)
    
    'Calculate new position of camera eye
    vectorToEye.TransformBy(rotationMtx)

    'Create new eye based on current target
    dim newEye = cam.Target.Copy()
    newEye.TranslateBy(vectorToEye)
    cam.Eye = newEye

    'Align up vector to Z axis
    cam.UpVector = zAxis.AsUnitVector()

    'Apply camera
    cam.Apply()
    'cam.ApplyWithoutTransition()

End Sub

 

Message 3 of 3
juliengoertz
in reply to: juliengoertz

Thank you! This is more than enough to get me going!

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

Post to forums  

Autodesk Design & Make Report