An undocumented? tip about UserInterface.messageBox

An undocumented? tip about UserInterface.messageBox

nnikbin
Collaborator Collaborator
1,005 Views
2 Replies
Message 1 of 3

An undocumented? tip about UserInterface.messageBox

nnikbin
Collaborator
Collaborator

The Fusion 360 API help describes the first argument of UserInterface.messageBox Method as "The message text to display in the dialog." but in practice it is able to show formatted texts.

 

Just like TextBoxCommandInput.formattedText property, formatted text includes any html formatting that has been defined. For example, you can use basic html formatting such as Bold, Italic,  line break, and even use img tag to insert images. Please take a look at the following image:

 

18.png

 

 

1,006 Views
2 Replies
Replies (2)
Message 2 of 3

JeromeBriot
Mentor
Mentor

Thank you @nnikbin 

 

Even if we should never rely on undocumented features until Autodesk make them official.

 

#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        msg = '<h1 style="background-color:DodgerBlue;">This is a formatted text box</h1>' \
              '<hr/>' \
              '<span style="color: red">Red</span> <span style="color: green">Green</span> <span style="color: blue">Blue</span><br/>' \
              '<b>Bold</b> <i>Italic</i> <u>Underline</u> <s>Stroke</s><br/>' \
              'x<sup>3</sup> + x<sup>2</sup> +  x = 0<br/>' \
              '&copy; &reg; &trade; $ &euro; &pound; &yen;<br/>' \
              '<a href="http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-A92A4B10-3781-4925-94C6-47DA85A4F65A">Fusion 360 API</a><br/>' \
              '<table">' \
              '<tr><th>A</th><th>B</th><th>C</th></tr>' \
              '<tr><td>1</td><td>2</td><td>3</td></tr>' \
              '<tr><td>4</td><td>5</td><td>6</td></tr>' \
              '</table>' \
              '<ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>' \
              '<ol><li>Item 1</li><li>Item 2</li><li>Item 3</li></ol>' \
              '<!-- Invisible -->' \
              '<div align="left">Left</div>' \
              '<div align="center">Center</div>' \
              '<div align="right">Right</div>'
              
        ui.messageBox(msg)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

messagebox-html.PNG

Message 3 of 3

nnikbin
Collaborator
Collaborator

Very nice sample. Thank you @JeromeBriot

0 Likes