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: 

Closing ui.messageBox with API?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
kmknights
392 Views, 4 Replies

Closing ui.messageBox with API?

Good morning all,

 

If we have a pop-up appear, is there any way to close the ui.messageBox with an external API command without the user needing to click 'ok' on the screen?

 

Thank you for your help!

Labels (1)
  • API
4 REPLIES 4
Message 2 of 5
BrianEkins
in reply to: kmknights

The API does not have anything to do this.

 

In the past, on Windows before .NET, I had a similar need and ended up using some low-level Windows API's to watch for a specific window to pop up and then mimic clicking the button to dismiss it.  I'm not sure how you might do something like that in Python and especially in a way that wouldn't be platform-specific.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 5
kandennti
in reply to: kmknights

If you just want to display and erase the message, why not use the CustomGraphicsText object?

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-4BF0DB87-C2BB-452C-BCD0-8BF6FE211171 

1.png

 

 

Here is a sample code that I tested, though it is incomplete.

#Fusion360API Python script
import adsk.core, adsk.fusion, traceback
import time

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        cGFact = CustomGraphicsFactry('piyo')
        msg = 'Hello World'
        font = 'Arial'
        showTime = 2.0

        cGFact.showTimerText(msg, font, showTime)

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

class CustomGraphicsFactry():
    _app = adsk.core.Application.cast(None)
    _cgGroup = adsk.fusion.CustomGraphicsGroup.cast(None)
    _id =''

    def __init__(self, id :str):
        self._app = adsk.core.Application.get()
        self._id = id

    def __del__(self):
        self.removeCG()

    def removeCG(self):
        des :adsk.fusion.Design = self._app.activeProduct
        cgs = [cmp.customGraphicsGroups for cmp in des.allComponents]
        cgs = [cg for cg in cgs if cg.count > 0]
        
        if len(cgs) < 1: return

        for cg in cgs:
            gps = [c for c in cg]
            gps.reverse()
            for gp in gps:
                if gp.id != self._id:
                    continue

                gp.deleteMe()

    def refreshCG(self):
        self.removeCG()
        des :adsk.fusion.Design = self._app.activeProduct
        comp :adsk.fusion.Component = des.activeComponent
        self._cgGroup = comp.customGraphicsGroups.add()
        self._cgGroup.id = self._id

    def showTimerText(
        self, 
        formattedText,
        font,
        showTime
        ):

        self.refreshCG()

        mat = adsk.core.Matrix3D.create()
        cgtxt = self._cgGroup.addText(formattedText, font, 1, mat)

        pntZero = adsk.core.Point3D.create(0,0,0)

        billBoard = adsk.fusion.CustomGraphicsBillBoard.create(pntZero)
        billBoard.billBoardStyle = adsk.fusion.CustomGraphicsBillBoardStyles.ScreenBillBoardStyle
        cgtxt.billBoarding = billBoard

        viewScale = adsk.fusion.CustomGraphicsViewScale.create(100, pntZero)
        cgtxt.viewScale = viewScale

        vp = _app.activeViewport
        x = vp.width * 0.3
        y = vp.height * 0.1
        viewPlace = adsk.fusion.CustomGraphicsViewPlacement.create(pntZero,
            adsk.fusion.ViewCorners.upperLeftViewCorner,
            adsk.core.Point2D.create(x,y))
        cgtxt.viewPlacement = viewPlace

        vp.refresh()
        time.sleep(showTime)
        self.removeCG()

 

Message 4 of 5
kmknights
in reply to: kandennti

Thank you very much for this suggestion and sample code! CustomGraphicsText seems to work really well, I wouldn't have thought of that. Appreciate your reply!

Message 5 of 5
en9y37
in reply to: kmknights

That was helpful to me too.

 

Thanks again  @kandennti !!!

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