htmlArgs.returnData not working with the new browser

htmlArgs.returnData not working with the new browser

tykapl.breuil
Advocate Advocate
516 Views
2 Replies
Message 1 of 3

htmlArgs.returnData not working with the new browser

tykapl.breuil
Advocate
Advocate

Hello everyone,

 

For an addin I'm working on I need to use the htmlArgs.returnData method, however it only works with the old browser, when you try to use it with you new browser, you get [object Promise] as a return value.

 

Sample code :

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

handlers = []
ui = None
app = adsk.core.Application.get()
ui = app.userInterface

# Event handler for the palette HTML event.
class MyHTMLEventHandler(adsk.core.HTMLEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            htmlArgs = adsk.core.HTMLEventArgs.cast(args)            
            htmlArgs.returnData = 'test'
        except:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))   

def run(context):
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        paletteId = 'TestPalette'
        palette = ui.palettes.itemById(paletteId)
        if palette:
            palette.isVisible = True
        else:
            palette = ui.palettes.add(
                paletteId,
                'test',
                'palette.html',
                True, #isVisible
                True, #showCloseButton
                True, #isResizable
                300, #width
                120, #height
                True #is New Browser
            )
            palette.dockingState = adsk.core.PaletteDockingStates.PaletteDockStateTop
            palette.isVisible = True
            onHTMLEvent = MyHTMLEventHandler()
            palette.incomingFromHTML.add(onHTMLEvent)
            handlers.append(onHTMLEvent)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def stop(context):
    try:        
        # Delete the palette created by this add-in.
        palette = ui.palettes.itemById('TestPalette')
        if palette:
            palette.deleteMe()
            
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
<!DOCTYPE html>
<html lang="ja">

<head>
  <meta charset="utf-8">
</head>

<body>

  <script>
    window.onload = function () {
        var adskWaiter = setInterval(function () {
          console.log('wait for adsk object');
          if (window.adsk) {
            clearInterval(adskWaiter);
                    alert(adsk.fusionSendData('test', 'test'))
          };
        }, 500);
      }
  </script>

</body>
</html>
0 Likes
517 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor

Hi @tykapl.breuil .

 

I, too, felt that "window.onload" was not working when I tried it in a new browser.

There may be another way to do it, but I didn't understand it well due to my lack of knowledge of JavaScript.

Therefore, I gave up using the new browser.

Message 3 of 3

BrianEkins
Mentor
Mentor

I'm able to reproduce the problem.  I need to check with the developers if this is expected behavior or a bug.  If it's expected, the documentation needs to be updated.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com