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: 

An undocumented? tip about UserInterface.messageBox

2 REPLIES 2
Reply
Message 1 of 3
nnikbin
563 Views, 2 Replies

An undocumented? tip about UserInterface.messageBox

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

 

 

2 REPLIES 2
Message 2 of 3
JeromeBriot
in reply to: nnikbin

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
in reply to: JeromeBriot

Very nice sample. Thank you @JeromeBriot

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