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: 

Changing the image of an ImageCommandInput

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
philipp.stein
144 Views, 2 Replies

Changing the image of an ImageCommandInput

Hi,

I am working on an add-in for Fusion, and want to update the image I show in the dialog, from within my InputChangedHandler. The creation of the new image can take some time, so I want to show a dummy image in the meantime. This is my code for that so far:

def notify(self, args):
        eventArgs = adsk.core.InputChangedEventArgs.cast(args)
        app = adsk.core.Application.get()
        ui = app.userInterface
        try:
            # access global variables
            global filePath, imgInput
            if eventArgs.input.id == 'getFile':
                # open a fileDialog
                fileDialog = ui.createFileDialog()
                fileDialog.isMultiSelectEnabled = False
                fileDialog.title = "Select Image"
                fileDialog.filter = 'Image Files (*.BMP;*.JPG;*.PNG)'
                fileDialog.filterIndex = 0
                dialogResult = fileDialog.showOpen()
                if dialogResult == adsk.core.DialogResults.DialogOK:
                    filePath = fileDialog.filename
                    # make ImageCommandInput visible and set the dummy image
                    imgInput.isVisible = True
                    imgInput.imageFile = "resources/load-icon.png"
                    # this can take some time
                    extractContours()
        except: 
            if ui:
                ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

The problem is, that the image is not updating before extractContours().

I would appreciate any help, thanks in advance! 

2 REPLIES 2
Message 2 of 3
BrianEkins
in reply to: philipp.stein

I don't think the dialog gets a chance to paint until after the event handler has finished.  I haven't tested this but you can try putting and adsk.doEvents() call right after you set the image.  If that doesn't work, I don't think it's currently possible.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3
philipp.stein
in reply to: BrianEkins

Thanks for your help, Works perfectly!

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