Receiving Leap Motion data via Python

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying to read in Leap Motion sensor data and set user parameters which are then used by a parameterized model using Python. I know that Fusion 360 (version 2.0.3257) supports Python 3.5.3:1880cd95a742 and the Leap Motion only has native support for Python 2.7. I followed Edwin's instructions here and generated a Python wrapper using the exact same version of Python that my version of Fusion is using.
I created a standalone Python 3.3 script to read the sensor data using the newly wrapped driver and it works fine. I'm trying to write an add-on in Fusion 360 to do the same thing and it crashes....every time. I'm new to API programming in Fusion 360 so I'm hoping this is just a newby mistake someone can help with.
Stripping out the rest of the program, I just took a default add-in template, imported the Leap library and tried to instantiate an instance and register a listener which crashes. I'm not sure if i have to wrap the leap event trigger in a Fusion 360 custom event trigger, but if you can point me in the right direction, it would be appreciated.
import adsk.core, adsk.fusion, adsk.cam, traceback, Leap # Globals _app = adsk.core.Application.cast(None) _ui = adsk.core.UserInterface.cast(None) _leap_controller = adsk.core.Application.cast(None) class SampleListener(Leap.Listener): def on_init(self, controller): print ("Initialized") def on_connect(self, controller): print ("Connected") def on_disconnect(self, controller): # Note: not dispatched when running in a debugger. print ("Disconnected") def on_exit(self, controller): print ("Exited") def run(context): ui = None try: global _app, _ui _app = adsk.core.Application.get() _ui = _app.userInterface _ui.messageBox('Hello addin') # Create a sample listener and controller global _leap_controller listener = SampleListener() _leap_controller = Leap.Controller() # Have the sample listener receive events from the controller _leap_controller.add_listener(listener) except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) def stop(context): global _ui _ui = None try: _app = adsk.core.Application.get() _ui = _app.userInterface _ui.messageBox('Stop addin') except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Registering of the listener is what is causing the crash.
Any insights are appreciated.
Sincerely, Paul.