Hi all.
I want to create an add-in that uses palettes, and I want to send the initial values for the palettes to be displayed from the python side, but I don't know how to do this.
In python, this is how I do it.
class MyHTMLEventHandler(adsk.core.HTMLEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
htmlArgs = adsk.core.HTMLEventArgs.cast(args)
data = json.loads(htmlArgs.data)
global _app
if htmlArgs.action == 'start':
args.returnData = 10
elif htmlArgs.action == 'sliderChange':
_app.log(data['value'])
except:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
In html, I do it like this.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<p>Slider</p>
<input type="range" min="1" max="149" step="1" id="slider"
onchange="sliderChange()">
</div>
<br />
</body>
<script>
window.onload = function(){
var args = {}
var angle = adsk.fusionSendData("start", JSON.stringify(args))
slider.value = angle
}
function sliderChange() {
var args = {
value: slider.value
}
adsk.fusionSendData("sliderChange", JSON.stringify(args))
}
</script>
</html>
This is due to my lack of knowledge in html + javascript.
I have confirmed that no HTML Event is generated in python when the palette is displayed.
If you know anything about this, please let me know.
I've attached all the code. When the add-in is run, the command is added to the following part
Solved! Go to Solution.
Solved by JeromeBriot. Go to Solution.
With the old web view in Fusion, you could right click and show the development console, showing you any Javascript errors. I'm not sure how it works in the new web view (using Chrome). I think you can force the old web view when creating the palette.
I have not touched this code in a long while, but I'm fairly certain it managed to fill data when the palette loaded. I went a bit overboard on the communication and made it a bit complex, but maybe it can give some ideas: https://github.com/thomasa88/VerticalTimeline
Thank you, @thomasa88 .
I don't know if you can understand it, but it helps me because I couldn't find a sample.
@thomasa88 a écrit :
With the old web view in Fusion, you could right click and show the development console, showing you any Javascript errors. I'm not sure how it works in the new web view (using Chrome). I think you can force the old web view when creating the palette.
First you have to activate the DevTools in the text commands window.
@kandennti, here is another example : Check Computer Specifications
See at the end of the file CheckComputerSpecs.js
@thomasa88 do you succeed in using the returnData property of the HTMLEventArgs object?
How the JS code should intercept this data?
Jérôme Briot, Freelance engineer - Mechanical design and prototyping
3D Print Plus / Pro | IDF Import | GitHub To Fusion 360 | Tube Bending Data Exchanger | Slice Data Export
Memory Used | Basic Calculator | Check Computer Specifications | Import spline from any CSV file
@JeromeBriotGood info!
Well, it looks like my code did handle the returnData, but have not run it since mid 2020:
Python, VerticalTimeline.py:
if html_commands:
htmlArgs.returnData = json.dumps(html_commands)
if html_commands:
htmlArgs.returnData = json.dumps(html_commands)
Javascript, palette.html
function query(action, data = {}) {
let ret = adsk.fusionSendData(action, JSON.stringify(data));
console.log("RET:", ret);
return JSON.parse(ret);
}
@thomasa88 thank you.
@kandennti See attached files.
Jérôme Briot, Freelance engineer - Mechanical design and prototyping
3D Print Plus / Pro | IDF Import | GitHub To Fusion 360 | Tube Bending Data Exchanger | Slice Data Export
Memory Used | Basic Calculator | Check Computer Specifications | Import spline from any CSV file
Thank you, @JeromeBriot .
It was complicated and I was about to cry.
I haven't looked at it in detail because I've been so busy and exhausted with work, but it's a clear sample.
@thomasa88 .
I felt again how powerful you are.
Thanks to both of you. I really appreciate it.
It's been a long time coming, but I've published an add-in that I created using the method you taught me.
It is in Japanese.
https://github.com/kantoku-code/Fusion360_PerspectiveAngleController
In order to be able to change the Perspective Angle, I really wanted to use a modaless dialog, so I used a palette.
I found out how to pass initial values in the new browser (QT Web Browser) and have attached a sample script.
The QT Web Browser is described as asynchronous in the documentation.
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-6C0C8148-98D0-4DBC-A4EC-D8E03A8A3B5B
<script>
document.addEventListener("DOMContentLoaded", () => {
let adskWaiter = setInterval(() => {
if (window.adsk) {
clearInterval(adskWaiter);
let element = document.getElementById("xxx");
adsk
.fusionSendData("DOMContentLoaded", "{}")
.then((data) =>
element.insertAdjacentHTML("afterend", "<p>" + data + "</p>")
);
}
}, 100);
});
</script>
The attached sample shows the name of the active document.
I have also confirmed that the same processing can be done with the palette, although it is displayed with the Browser Command Input.