Error when calling sendInfoToHTML
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I met an error when calling sendInfoToHTML.
Here is my code:
import adsk.core, adsk.fusion, traceback myPalette = 'myPalette' # global set of event handlers to keep them referenced for the duration of the command handlers = [] ui = None def run(context): ui = None try: app = adsk.core.Application.get() global ui ui = app.userInterface palette = ui.palettes.itemById(myPalette) if palette: palette.deleteMe() palette = ui.palettes.add(myPalette, 'My Palette', 'palette.html', True, True, True, 300, 200) # Dock the palette to the right side of Fusion window. palette.dockingState = adsk.core.PaletteDockingStates.PaletteDockStateRight palette.sendInfoToHTML('send', 'some info') except: if ui: ui.messageBox('AddIn Start Failed: {}'.format(traceback.format_exc())) def stop(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface palette = ui.palettes.itemById(myPalette) if palette: palette.deleteMe() except: if ui: ui.messageBox('AddIn Stop Failed: {}'.format(traceback.format_exc()))
<!DOCTYPE html> <html> <head> </head> <body> <p id='p1'>Click the button below or use the "Send info to HTML" command in the ADD-INS panel.</p> <button type='button' onclick='sendInfoToFusion()'>Click to send info to Fusion</button> <br /><br /> </body> <script> function sendInfoToFusion(){ var args = { arg1 : "Sample argument 1", arg2 : "Sample argument 2" }; adsk.fusionSendData('send', JSON.stringify(args)); } window.fusionJavaScriptHandler = {handle: function(action, data){ try { if (action == 'send') { // Update a paragraph with the data passed in. document.getElementById('p1').innerHTML = data; } else if (action == 'debugger') { debugger; } else { return 'Unexpected command type: ' + action; } } catch (e) { console.log(e); console.log('exception caught with command: ' + action + ', data: ' + data); } return 'OK'; }}; </script> </html>