Message 1 of 3
htmlArgs.returnData not working with the new browser
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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>