Hi There,
I am looking for a way to create a turntable of my model using I logic.
The code I already have is a mix of multiple forum posts. but I can't get it to work.
Can I get some help on this.
I want to rotate the view around the Z axis from the starting point where the camera is.
When using this code, The camera goes first to a certain point and I don't know where that is.
The final output for the app wil be a html turntable to put on websites.
Thanks in advance.
' Get the active camera. Dim cam As Camera cam = ThisApplication.ActiveView.Camera Dim tg As TransientGeometry tg = ThisApplication.TransientGeometry ' Define the number of steps in the animation. Dim steps As Integer steps = 40 ' Iterate the specified number of steps. Dim i As Integer For i = 1 To steps cam.Fit() cam.Perspective = 0 cam.ViewOrientationType= 10764 'cam.UpVector = tg.CreateUnitVector(0, 0, 0) cam.Eye = tg.CreatePoint(0,i,0) cam.ApplyWithoutTransition Next
Solved! Go to Solution.
Hi
Here is a VBA sample that rotates the model dynamically of 360 degrees around Y axis:
Public Sub RotateCamMacro() Dim pi As Double pi = Math.Atn(1) * 4 'Rotation speed in Rad/Sec Dim rotSpeedRad As Double rotSpeedRad = 40 * pi / 180 'Get part document Dim doc As Document Set doc = ThisApplication.ActiveDocument 'Get range box center point Dim centerPoint As point Set centerPoint = GetRangeBoxCenter(doc) 'Set camera orientation Call SetCameraOrientation( _ centerPoint, _ ViewOrientationTypeEnum.kIsoTopRightViewOrientation) 'Get Inventor camera Dim camera As Inventor.camera Set camera = ThisApplication.ActiveView.camera Dim totalRot As Double totalRot = 0 Dim offsetRad As Double Dim rotAxis As vector Set rotAxis = ThisApplication.TransientGeometry.CreateVector(0, 1, 0) Dim upVector As UnitVector Set 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 Set minPoint = doc.ComponentDefinition.RangeBox.minPoint Dim maxPoint As point Set maxPoint = doc.ComponentDefinition.RangeBox.maxPoint Set 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 Set 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 Set matrix = ThisApplication.TransientGeometry.CreateMatrix Call matrix.SetToRotation(offsetRad, rotAxis, center) Dim newEye As point Set newEye = camera.eye Call newEye.TransformBy(matrix) camera.eye = newEye camera.upVector = upVector Call camera.ApplyWithoutTransition End Sub
Regards,
Philippe.
Can't find what you're looking for? Ask the community or share your knowledge.