Changing the image of an ImageCommandInput

Changing the image of an ImageCommandInput

Anonymous
Not applicable
458 Views
2 Replies
Message 1 of 3

Changing the image of an ImageCommandInput

Anonymous
Not applicable

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! 

0 Likes
Accepted solutions (1)
459 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor
Accepted solution

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
0 Likes
Message 3 of 3

Anonymous
Not applicable

Thanks for your help, Works perfectly!

0 Likes