Event when HTML is loaded and ready?

Event when HTML is loaded and ready?

sophiadoan
Contributor Contributor
556 Views
4 Replies
Message 1 of 5

Event when HTML is loaded and ready?

sophiadoan
Contributor
Contributor

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 

0 Likes
Accepted solutions (1)
557 Views
4 Replies
Replies (4)
Message 2 of 5

kandennti
Mentor
Mentor

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.

0 Likes
Message 3 of 5

sophiadoan
Contributor
Contributor

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.

0 Likes
Message 4 of 5

kandennti
Mentor
Mentor
Accepted solution

@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', '');
		}
	});
});
0 Likes
Message 5 of 5

sophiadoan
Contributor
Contributor

@kandennti 

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

 

Thank you very much