<?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 Re: Trying to create a Python script to animate Fusion 360 camera in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trying-to-create-a-python-script-to-animate-fusion-360-camera/m-p/5666476#M21182</link>
    <description>&lt;P&gt;Wow, that really solves my problem! Thanks. That adsk.doEvents call was exactly what I was looking for.&lt;/P&gt;</description>
    <pubDate>Fri, 05 Jun 2015 15:29:20 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-06-05T15:29:20Z</dc:date>
    <item>
      <title>Trying to create a Python script to animate Fusion 360 camera</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trying-to-create-a-python-script-to-animate-fusion-360-camera/m-p/5665353#M21180</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to&amp;nbsp;write a Python script to animate the camera so that it circles the currently selected model. I can programmatically manipulate the camera in&amp;nbsp;Python, but I can't figure out how to do it within a loop, because I keep locking up the program (running an infinite loop in a script seems to hog execution from doing anything in the Fusion 360 UI, so it locks up). I'm wondering if there are multithreading/delegate solutions that may work. I took a few minutes to try calling a method to move the camera via threading.Timer, but&amp;nbsp;it's not working. I am not a Python master by any means, so there might be something simple I'm missing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran a few Google searches and looked through this forum, the example code, and the API documentation, and I am still a bit stumped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the last script I tried (I was just trying to update the camera once from a separate thread at this point, and by the way, I couldn't even get the timer executed method to print to the console. I do understand if the console stream is a resource only available from the main thread though):&lt;/P&gt;&lt;PRE&gt;import adsk.core, adsk.fusion, traceback, threading

def move_camera():
    global app
    global camera
    eye = camera.eye
    eye.x += 1.0
    eye.y += 1.0
    eye.z += 1.0
    camera.eye = eye
    
    target = camera.target
    target.x += 1.0
    target.y += 1.0
    target.z += 1.0
    camera.target = target
    
    camera.isSmoothTransition = False
    app.activeViewport.camera = camera
    app.activeViewport.refresh()
    
    print('hello from a timer call')
  

def main():
  ui = None
  
  global app
  global camera
  try:
    print('hello, world')
    app = adsk.core.Application.get()
    camera = app.activeViewport.camera
    t = threading.Timer(0.1, move_camera)
    t.start()
    
  except:
    if ui:
      ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
      
main()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fusion 360 is a really neat program by the way. ...and thanks for reading!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2015 21:24:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trying-to-create-a-python-script-to-animate-fusion-360-camera/m-p/5665353#M21180</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-06-04T21:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a Python script to animate Fusion 360 camera</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trying-to-create-a-python-script-to-animate-fusion-360-camera/m-p/5665514#M21181</link>
      <description>&lt;P&gt;Here's a modified version of your program that behaves as I would expect.&amp;nbsp; I changed it so the move_camera now has a loop so the camera is being animated and the big change, (which was probably causing your problem), is that&amp;nbsp;I added a call&amp;nbsp;to the doEvents function.&amp;nbsp; Python runs in-process to Fusion and apparrently&amp;nbsp;Fusion isn't able to keep up with the event queue as these API calls are being made.&amp;nbsp; Calling doEvents gives it a chance to catch up&amp;nbsp;each time the camera is set.&amp;nbsp; If I comment out the doEvents call it functions correctly for about half&amp;nbsp;the rotation and then Fusion freezes up until it's finished the full rotation and then the&amp;nbsp;view refreshes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;import adsk.core, adsk.fusion, traceback, math

def move_camera(app, view):
    try:
        camera = view.camera
        
        target = adsk.core.Point3D.create(0,0,0)
        up = adsk.core.Vector3D.create(0,0,1)
        steps = 1000
        
        dist = camera.target.distanceTo(camera.eye)
    
        for i in range(0, steps):
            eye = adsk.core.Point3D.create(dist * math.cos((math.pi*2) * (i/steps)), dist * math.sin((math.pi*2) * (i/steps)), 10)
            
            camera.eye = eye
            camera.target = target
            camera.upVector = up
        
            camera.isSmoothTransition = False
            view.camera = camera
            adsk.doEvents()
            view.refresh()
    except:
        ui = app.userInterface
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def main():
    ui = None
  
    try:
        print('hello, world')
        app = adsk.core.Application.get()
        move_camera(app, app.activeViewport)
    
    except:
        ui = app.userInterface
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

      
main()&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2015 00:02:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trying-to-create-a-python-script-to-animate-fusion-360-camera/m-p/5665514#M21181</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2015-06-05T00:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a Python script to animate Fusion 360 camera</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trying-to-create-a-python-script-to-animate-fusion-360-camera/m-p/5666476#M21182</link>
      <description>&lt;P&gt;Wow, that really solves my problem! Thanks. That adsk.doEvents call was exactly what I was looking for.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2015 15:29:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trying-to-create-a-python-script-to-animate-fusion-360-camera/m-p/5666476#M21182</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-06-05T15:29:20Z</dc:date>
    </item>
  </channel>
</rss>

