- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
I am developing a Javascript add-in with an accompanying HTML palette. I am currently trying to get the back and forth communication set up, but I can't get it to work in either direction.
When I try to send info to the add-in from the palette, Fusion freezes completely and I have to close it with the task manager. This only happens when the add-in has attached a listener to the receive event via "palette.incomingFromHTML.add(onHtmlReceiveEvent);" and the palette attempts to send via "adsk.fusionSendData();" (with a button click). At the moment, the callback does nothing but display a message box.
When I try to send info to the palette from the add-in, I get a "InternalValidationError: !response.empty()" error. I know that when add-ins send to the palette, it expects a string to be returned in response, but I still get this error whether I return something or not. The palette does load jQuery and a few other plugins (locally) so in order to eliminate the possibly that Fusion is sending before the palette has had a chance to attach the handler, I delayed "palette.sendInfoToHTML()" with setTimeout(). These stops the !response.empty() error, but if the timeout is more than 100-150 ms, Fusion freezes up.
I have successfully duplicated the add-in/palette example given here, but that is a Python sample. The docs don't provide full samples for Javascript, and there are none elsewhere online. I've stripped everything down to the bare essentials to no successs so I'm at a total loss. I fear it may be an internal problem.
Only relevant parts of my code are below. When the add-in is run, it sets up a command and then the palette. The palette itself does load jQuery and a few other plugins.
Thanks in advance for any assistance!
- A. Babin
Javascript Add-in (Relevant code only)
var makePalette = function(args) {
try {
if (ui) {
var palette = ui.palettes.itemById(paletteId);
if (!palette) {
palette = ui.palettes.add(paletteId, 'Param Master', paletteHtmlLocation, true, true, true, 300, 200);
palette.dockingState = 3;
palette.closed.add(OnClosePalette);
} else {
palette.isVisible = true;
}
palette.incomingFromHTML.add(onHtmlReceiveEvent);
}
} catch (e) {
ui.messageBox('Failed to execute command : ' + (e.description ? e.description : e));
}
}
var OnCommandCreated = function(args) {
try {
//Set up and show palette.
makePalette();
//Attempt to delay add-in to palette comm.
//setTimeout(function() {
// palette.sendInfoToHTML('send', "Hello?");
//}, 3000);
} catch (e) {
ui.messageBox('Failed to execute command : ' + (e.description ? e.description : e));
}
}
var onHtmlReceiveEvent = function(args) {
eventArgs = adsk.core.HTMLEventArgs(args);
ui.messageBox("RECEIVED");
}
Palette (Relevant code only)
function sendInfoToFusion(){
adsk.fusionSendData('send', "Hello");
}
window.fusionJavaScriptHandler = {handle: function(action, data){
return "OK";
}};
Solved! Go to Solution.
