Display image in UI depending on user input

Display image in UI depending on user input

brad.bylls
Collaborator Collaborator
881 Views
6 Replies
Message 1 of 7

Display image in UI depending on user input

brad.bylls
Collaborator
Collaborator

I am working on a script that starts with a user button group in the UI:

        # Define the command dialog.
        radioButtonGroup = inputs.addRadioButtonGroupCommandInput('radioButtonGroup''Support Plate?')
        radioButtonItems = radioButtonGroup.listItems
        radioButtonItems.add("Yes"False)
        radioButtonItems.add("No"False)
 
When the user makes a selection 'Yes' or 'No'
I have this in the inputChanged method :
    if changed_input.id == 'radioButtonGroup':
        strResult = inputs.itemById('radioButtonGroup').selectedItem.name
        if strResult == "Yes":
            inputs.addImageCommandInput('baseImage''''commands/resources/command_icons/MBA/MBA.png')
        else:
            inputs.addImageCommandInput('baseImage''''commands/resources/command_icons/MBB/MBB.png')
Nothing changes in the UI.
I saw something about adding adsk.doEvents() right after inputs.addImage CommandInput() statements, but that also did nothing.
I am sure I am missing something but can't find what it might be.
Brad Bylls
Accepted solutions (1)
882 Views
6 Replies
Replies (6)
Message 2 of 7

nnikbin
Collaborator
Collaborator

Because CommandInputs Object has no methods for removing CommandInput(s) I guess add-ins are only allowed to add command inputs in CommandCreatedEventHandler.notify Method. I guess the only way to dynamically add command inputs outside CommandCreatedEventHandler.notify method is adding some of them (which are supported) to new cells of TableCommandInput. (Please note that I am NOT hundred percent sure that what I said above is correct. It is just a guess based on my experience).

 

For your case I think you can create both ImageCommandInput(s), then change the visibility of them using ImageCommandInput.isVisible property.

 

 

0 Likes
Message 3 of 7

nnikbin
Collaborator
Collaborator

You can also change image using ImageCommandInput.imageFile property

0 Likes
Message 4 of 7

BrianEkins
Mentor
Mentor
Accepted solution

It is possible to delete existing command inputs by using the deleteMe method on the CommandInput object. You can also add new command inputs but there's a limitation with this in that they are always added at the bottom of the existing command inputs. You don't have any control over the position.

 

If I'm designing a dialog where some of it is dynamic based on the value of other inputs, I'll typically create all of the inputs when the command is created but set the isVisible property to False for those that currently shouldn't be seen.  I then just set the isVisible property of the various inputs depending on what should be displayed.  You can also change the values of the existing command inputs.  As @nnikbin mentioned, you can set the property that controls which bitmap is being used by a command input.  That gives you even more flexibility.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 7

nnikbin
Collaborator
Collaborator

@BrianEkins , when I use deleteMe method inside notify method of InputChangedEventHandler, it deletes the commandInput but nothing will be changed in UI. The commandInput will be still visible. Similarly when I add commandInput(s) inside notify method of InputChangedEventHandler, for example by clicking on a button, a commandInput will be created but it is not displayed in dialog. Examining its isVisible property shows it is false. Even setting isVisible to true does not display it.

0 Likes
Message 6 of 7

nnikbin
Collaborator
Collaborator

It seems dynamically adding commandInputs to GroupCommandInput and deleting commandInputs from GroupCommandInput is possible. But I was not able to add them to or delete them from root dialog dynamically. All my tests were on Windows (not Mac).

0 Likes
Message 7 of 7

BrianEkins
Mentor
Mentor

All of the Fusion commands create all of the inputs during the command create.  They play with the visibility show the inputs that are currently needed.  The exception to this is the table command input.  Inputs are added and removed dynamically for tables.  The API is exposing the internal functionality and because functionality besides this isn't needed by Fusion other uses weren't designed for and haven't been tested so it's a matter of experimenting to see what happens to work.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com