- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there,
I am trying to write a Python script to animate the camera so that it circles the currently selected model. I can programmatically manipulate the camera in 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 it's not working. I am not a Python master by any means, so there might be something simple I'm missing
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.
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):
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()
Fusion 360 is a really neat program by the way. ...and thanks for reading!
Solved! Go to Solution.
