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: 

htmlArgs.returnData not working with the new browser

2 REPLIES 2
Reply
Message 1 of 3
tykapl.breuil
203 Views, 2 Replies

htmlArgs.returnData not working with the new browser

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>
2 REPLIES 2
Message 2 of 3
kandennti
in reply to: tykapl.breuil

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
in reply to: tykapl.breuil

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

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