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: 

Event when HTML is loaded and ready?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
sophiadoan
163 Views, 4 Replies

Event when HTML is loaded and ready?

I tried to sendInfoToHTML within CommandEventHandler which triggers after CommandCreatedEvent but the Palette does not response. May be because it has not been loaded and ready to receive? 

I need to send data before user has a chance to click any thing on the palette.

I hope I don't have to spawn a task to poll for ready status.

 

Thank you 

4 REPLIES 4
Message 2 of 5
kandennti
in reply to: sophiadoan

Hi @sophiadoan .

 

I interpreted the initial value of the palette display to mean that you want Fusion360 to send some data to be displayed.

 

On the JavaScript side, use the DOMContentLoaded event to call the adsk.fusionSendData function.
On the C++ side, pick up the DOM side call with the incomingFromHTML event and send the necessary data to the JavaScript side using HTMLEventArgs.returnData.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-DC2A4AB7-6A24-4A28-87A0-9952A0ABDF74 

 

The content is in python, but I also learned it here.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/i-want-to-set-the-initial-values-for-the-p... 

Note that the new browser (QT Web Browser) is asynchronous.

Message 3 of 5
sophiadoan
in reply to: sophiadoan

window.addEventListener('DOMContentLoaded', (event) => {
adsk.fusionSendData('domLoaded', '');
});

above event did fired, but this is what I see in the Console error output:

VM41 ImagePanel.html:104 Uncaught ReferenceError: adsk is not defined
at VM41 ImagePanel.html:104

???

and HTMLEventHandler never get called until some button is clicked on the palette.

Message 4 of 5
kandennti
in reply to: sophiadoan

@sophiadoan .

 

We could not reproduce the same error here.

 

Does JavaScript give the same error when I do this?

document.addEventListener('DOMContentLoaded', () => {
	let adskWaiter = setInterval(() => {
		if (window.adsk) {
			clearInterval(adskWaiter);
			adsk.fusionSendData('domLoaded', '');
		}
	});
});
Message 5 of 5
sophiadoan
in reply to: kandennti

@kandennti 

I did not use polling (setInterval), with it now it works!

 

Thank you very much

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