I want to set the initial values for the palette display

kandennti
Mentor
Mentor

I want to set the initial values for the palette display

kandennti
Mentor
Mentor

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

1.png

 

0 Likes
Reply
Accepted solutions (1)
819 Views
8 Replies
Replies (8)

thomasa88
Advocate
Advocate

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

1 Like

kandennti
Mentor
Mentor

Thank you, @thomasa88 .

 

I don't know if you can understand it, but it helps me because I couldn't find a sample.

 

0 Likes

JeromeBriot
Mentor
Mentor

@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?

 

 

1 Like

thomasa88
Advocate
Advocate

@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);        
    }
2 Likes

JeromeBriot
Mentor
Mentor
Accepted solution
1 Like

kandennti
Mentor
Mentor

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.

 

0 Likes

kandennti
Mentor
Mentor

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.

2 Likes

kandennti
Mentor
Mentor

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 

1.png

 

 

  <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.

 

0 Likes