Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Receiving Leap Motion data via Python

3 REPLIES 3
Reply
Message 1 of 4
thekestrel
1237 Views, 3 Replies

Receiving Leap Motion data via Python

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.

 

Tags (2)
3 REPLIES 3
Message 2 of 4
marshaltu
in reply to: thekestrel

Hello,

 

I tried to reproduce the crash you mentioned by your sample. Unfortunately it didn't work for me because "Leap" module cannot be loaded(I downloaded the module from the link which Edwin shared). It would be good if you can send me (marshal dot tu at autodesk dot com) a copy of leap module you used. I was assuming the sample can be run without leap motion sensor. Or, I am not sure if you submitted crash report when you got crash? If yes, please share me the report id or email address you filled in crash report dialog. 

 

I am not familiar with leap listener. Does it need to always run in main thread? If not, it would be worth trying to move it to worker thread and custom event can be used if you want to update parameters of design in Fusion 360.

 

Thanks,

Marshal 

 



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 3 of 4
albin-w
in reply to: thekestrel

Any updates on integrating leapmotion into fusion 360? 

Message 4 of 4
marshaltu
in reply to: albin-w

Hello,

 

Sorry for late update.

 

I received the email from Paul about sample codes and reproducible steps. I cannot reproduced the crash issue and just sent reply to Paul for more information. However I didn't get response yet.

 

Some information I appended in the reply was "I didn’t have a Leap sensor for testing. I just run the addin and then stop it. I observed “on_init” and “on_exit” were called." I am not sure if it was because I didn't have leap sensor so that I cannot see the issue you mentioned.

 

Thanks,

Marshal 



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report