<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Turntable View Rotation in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/turntable-view-rotation/m-p/7862407#M82104</link>
    <description>&lt;P&gt;I have created a turntable VBA macro that works in most cases but is a bit buggy depending on the initial view.&lt;/P&gt;&lt;P&gt;The rotation is about the Z axis and the issues occur when looking directly up or down the axis (Top or Bottom view)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The fault is the view jumps to a new position, the rotation starts doesn't compete 360 deg, then model disappears until clicking in the graphics window.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could fix it by setting the view to home before rotating but would prefer to use any view if possible to make it more flexible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions how to improve it would be appreciated. &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@B4D44A73814D7FC0D950DEDFACB97081/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Sub Turntable()

' Define Pi.
    Dim pi As Double
    pi = Math.Atn(1) * 4

'Rotation speed in Rad/Sec
    Dim rotSpeedRad As Double
    rotSpeedRad = 30 * pi / 180

'Define &amp;amp; check current document type
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    If oDoc.DocumentType = kDrawingDocumentObject Then GoTo Finished

'Get center point of the model
    Dim centerPoint As Point
    Dim minPoint As Point
    Set minPoint = oDoc.ComponentDefinition.RangeBox.minPoint
    Dim maxPoint As Point
    Set maxPoint = oDoc.ComponentDefinition.RangeBox.maxPoint
    Set centerPoint = ThisApplication.TransientGeometry.CreatePoint(    (minPoint.X + maxPoint.X) * 0.5, (minPoint.Y + maxPoint.Y) * 0.5, (minPoint.Z + maxPoint.Z) * 0.5)
    
'Camera and tuntable rotation
    Dim camera As Inventor.camera
    Set camera = ThisApplication.ActiveView.camera
    Dim totalRot As Double
    totalRot = 0

'Define rotation increment and axis
    Dim offsetRad As Double
    Dim rotAxis As Vector
    Set rotAxis = ThisApplication.TransientGeometry.CreateVector(0, 0, 1)

'Rotate view
    Dim upVector As UnitVector
    Set upVector = ThisApplication.TransientGeometry.CreateUnitVector(0, 0, 1)
    Do While (totalRot &amp;lt; 2 * pi)
    offsetRad = 0.05 * rotSpeedRad
    RotateCam camera, offsetRad, rotAxis, centerPoint, upVector
    totalRot = totalRot + offsetRad
    Loop

Finished:

End Sub

Public Sub RotateCam(camera As camera, ByVal offsetRad As Double, 
rotAxis As Vector, centerPoint As Point, upVector As UnitVector)

Dim matrix As matrix
Set matrix = ThisApplication.TransientGeometry.CreateMatrix
Call matrix.SetToRotation(offsetRad, rotAxis, centerPoint)
Dim newEye As Point
Set newEye = camera.Eye
Call newEye.TransformBy(matrix)
camera.Eye = newEye
camera.upVector = upVector
Call camera.ApplyWithoutTransition

End Sub&lt;/PRE&gt;&lt;P&gt;It is based on code from here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-customization/controlling-the-camera-using-ilogic/m-p/5040336/highlight/true#M49911" target="_blank"&gt;https://forums.autodesk.com/t5/inventor-customization/controlling-the-camera-using-ilogic/m-p/5040336/highlight/true#M49911&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 17 Mar 2018 20:59:12 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-03-17T20:59:12Z</dc:date>
    <item>
      <title>Turntable View Rotation</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/turntable-view-rotation/m-p/7862407#M82104</link>
      <description>&lt;P&gt;I have created a turntable VBA macro that works in most cases but is a bit buggy depending on the initial view.&lt;/P&gt;&lt;P&gt;The rotation is about the Z axis and the issues occur when looking directly up or down the axis (Top or Bottom view)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The fault is the view jumps to a new position, the rotation starts doesn't compete 360 deg, then model disappears until clicking in the graphics window.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could fix it by setting the view to home before rotating but would prefer to use any view if possible to make it more flexible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions how to improve it would be appreciated. &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@B4D44A73814D7FC0D950DEDFACB97081/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Sub Turntable()

' Define Pi.
    Dim pi As Double
    pi = Math.Atn(1) * 4

'Rotation speed in Rad/Sec
    Dim rotSpeedRad As Double
    rotSpeedRad = 30 * pi / 180

'Define &amp;amp; check current document type
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    If oDoc.DocumentType = kDrawingDocumentObject Then GoTo Finished

'Get center point of the model
    Dim centerPoint As Point
    Dim minPoint As Point
    Set minPoint = oDoc.ComponentDefinition.RangeBox.minPoint
    Dim maxPoint As Point
    Set maxPoint = oDoc.ComponentDefinition.RangeBox.maxPoint
    Set centerPoint = ThisApplication.TransientGeometry.CreatePoint(    (minPoint.X + maxPoint.X) * 0.5, (minPoint.Y + maxPoint.Y) * 0.5, (minPoint.Z + maxPoint.Z) * 0.5)
    
'Camera and tuntable rotation
    Dim camera As Inventor.camera
    Set camera = ThisApplication.ActiveView.camera
    Dim totalRot As Double
    totalRot = 0

'Define rotation increment and axis
    Dim offsetRad As Double
    Dim rotAxis As Vector
    Set rotAxis = ThisApplication.TransientGeometry.CreateVector(0, 0, 1)

'Rotate view
    Dim upVector As UnitVector
    Set upVector = ThisApplication.TransientGeometry.CreateUnitVector(0, 0, 1)
    Do While (totalRot &amp;lt; 2 * pi)
    offsetRad = 0.05 * rotSpeedRad
    RotateCam camera, offsetRad, rotAxis, centerPoint, upVector
    totalRot = totalRot + offsetRad
    Loop

Finished:

End Sub

Public Sub RotateCam(camera As camera, ByVal offsetRad As Double, 
rotAxis As Vector, centerPoint As Point, upVector As UnitVector)

Dim matrix As matrix
Set matrix = ThisApplication.TransientGeometry.CreateMatrix
Call matrix.SetToRotation(offsetRad, rotAxis, centerPoint)
Dim newEye As Point
Set newEye = camera.Eye
Call newEye.TransformBy(matrix)
camera.Eye = newEye
camera.upVector = upVector
Call camera.ApplyWithoutTransition

End Sub&lt;/PRE&gt;&lt;P&gt;It is based on code from here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-customization/controlling-the-camera-using-ilogic/m-p/5040336/highlight/true#M49911" target="_blank"&gt;https://forums.autodesk.com/t5/inventor-customization/controlling-the-camera-using-ilogic/m-p/5040336/highlight/true#M49911&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 20:59:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/turntable-view-rotation/m-p/7862407#M82104</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-17T20:59:12Z</dc:date>
    </item>
  </channel>
</rss>

