Problem with Javascript: Palette.sendInfoToHTML returns no response

Problem with Javascript: Palette.sendInfoToHTML returns no response

j.han97
Advocate Advocate
766 Views
6 Replies
Message 1 of 7

Problem with Javascript: Palette.sendInfoToHTML returns no response

j.han97
Advocate
Advocate

Hi all, 

 

I am developing a palette recently and it worked fine until just now. The Javascript suddenly just refused to return anything. 

 

To identify the problem, I have created a sample to replicate this problem. With a simple palette that connects to a HTML with only "Hello World" as plain text, this script then sends a simple 'hi' message to the HTML.

 

However, the same error persists and show 'response empty' message.

jhan97_0-1641372288029.png

 

I am not experienced in Javascript, hence have no idea how to debug this problem. I have restarted Fusion 360 as well, but no help in this issue.

 

Thank you in advance for your kind help.

 

 

0 Likes
Accepted solutions (3)
767 Views
6 Replies
Replies (6)
Message 2 of 7

j.han97
Advocate
Advocate

Ok, now I think the Fusion 360 on my computer is broken. When I ran this script:

import adsk.core, adsk.fusion, adsk.cam, traceback

_app = adsk.core.Application.get()
_ui = _app.userInterface

def run(context):
    try:
        _ui.messageBox('Hello world')

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def stop(context):
    if _ui:
        _ui.messageBox('Bye bye world')

 The 'Hello world' dialog popped out first, then followed by 'Bye bye world' immediately. Seems like Fusion 360 is rushing from run() to stop() recklessly. I will re-install and see if the problem goes away.

0 Likes
Message 3 of 7

j.han97
Advocate
Advocate
Accepted solution

After a clean re-install, Fusion 360 is working normally now. (Although I don't know if it will snap again someday) 

 

As a side note, I am experiencing some connectivity issues to Autodesk servers (pure speculation), so the problem might be rooting from there (pure speculation).

 

Anyway, the problem is gone for now, so I will mark this post as solved.

Message 4 of 7

kandennti
Mentor
Mentor
Accepted solution

Hi @j.han97 .

 

When sending data from python to Html, it is useful to set it with json.dumps against HTMLEventArgs.returnData property.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-DC2A4AB7-6A24-4A28-87A0-9952A0ABDF74 

 

I also have very little experience with JavaScript, but I learned it from @thomasa88  and @JeromeBriot.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/i-want-to-set-the-initial-values-for-the-p... 

 

And I was able to publish this one.

https://github.com/kantoku-code/Fusion360_PerspectiveAngleController 

Message 5 of 7

j.han97
Advocate
Advocate

Thank you @kandennti for the useful information. I definitely need them to make my code more robust.

 

Besides that, the developer mode mentioned in your post sounds very interesting to me. Since the html is implemented in Fusion 360 (kind of indirect), plus I am not very familiar with Javascript, it is extremely frustrating for me to debug the script. With the developer tools I expect to develop my script more efficiently.

0 Likes
Message 6 of 7

j.han97
Advocate
Advocate
Accepted solution

Thanks to the tips on the developer tools in Fusion 360, I was able to find the problem. There is a mistyped function at the beginning (variable declaration) of the Javascript, which caused the whole script to fail and not returning everything.

 

So lesson learnt: If Javascript gives empty response, check the script!!

 

 

Message 7 of 7

rishabsain723
Participant
Participant

Great! this is helpful, thanks for sharing.