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: 

GroupCommandInput with checkbox does not behave as expected

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
nnikbin
741 Views, 4 Replies

GroupCommandInput with checkbox does not behave as expected

When GroupCommandInput.isEnabledCheckBoxDisplayed is set to True, despite the expected behavior, isEnabled property will always be True regardless of the group command input checkbox state. isEnabled property will be false only when we set it to false by code.

 

Here are some captured images showing this behavior:

 

Capture_06.png

  

Capture_07.png

  

Capture_05.png

 

I was not able to find any method for getting the checked state of group command input checkbox.

 

Here is my sample code for demonstrating this issue:

 

import adsk.core, adsk.fusion, traceback

app = None
ui  = None
commandId = 'TestGroupCommandInput'
commandName = 'Test Group Command Input'
commandDescription = 'Test group command input'

handlers = []

class MyCommandInputChangedHandler(adsk.core.InputChangedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            cmd = args.firingEvent.sender
            inputs = cmd.commandInputs
            cmdInput = args.input
            groupCmdInput = inputs.itemById(commandId + '_group')
            checkBox1CommandInput = inputs.itemById(commandId + '_checkBox1')
            
            if cmdInput.id == commandId + '_TestButton':
                ui.messageBox('Group -> isEnabled: ' + str(groupCmdInput.isEnabled) + '\n' + 'Check Box 1 -> isEnabled: ' + str(checkBox1CommandInput.isEnabled))
            elif cmdInput.id == commandId + '_ChangeByCodeButton':
                groupCmdInput.isEnabled = not(groupCmdInput.isEnabled)
            return True
        except:
            if ui:
                ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class MyCommandDestroyHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            adsk.terminate()
        except:
            if ui:
                ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class MyCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            cmd = args.command
            onDestroy = MyCommandDestroyHandler()
            cmd.destroy.add(onDestroy)
            
            onInputChanged = MyCommandInputChangedHandler()
            cmd.inputChanged.add(onInputChanged)
            
            handlers.append(onDestroy)
            handlers.append(onInputChanged)
            inputs = cmd.commandInputs
            global commandId

            groupCmdInput = inputs.addGroupCommandInput(commandId + '_group', 'Group')
            groupCmdInput.isExpanded = True
            groupCmdInput.isEnabledCheckBoxDisplayed = True
            groupChildInputs = groupCmdInput.children
            
            checkBox1CommandInput = groupChildInputs.addBoolValueInput(commandId + '_checkBox1', 'Check Box 1', True)
            checkBox2CommandInput = groupChildInputs.addBoolValueInput(commandId + '_checkBox2', 'Check Box 2', True)
            
            testButtonCommandInput = inputs.addBoolValueInput(commandId + '_TestButton', 'Test Enabled States', False)
            changeByCodeButtonCommandInput = inputs.addBoolValueInput(commandId + '_ChangeByCodeButton', 'Change Enabled State By Code', False)
            testButtonCommandInput.isFullWidth = True
            changeByCodeButtonCommandInput.isFullWidth = True  
        except:
            if ui:
                ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def run(context):
    ui = None
    try:
        global app
        app = adsk.core.Application.get()
        global ui
        ui = app.userInterface

        global commandId
        global commandName
        global commandDescription

        cmdDef = ui.commandDefinitions.itemById(commandId)
        if not cmdDef:
            cmdDef = ui.commandDefinitions.addButtonDefinition(commandId, commandName, commandDescription)

        onCommandCreated = MyCommandCreatedHandler()
        cmdDef.commandCreated.add(onCommandCreated)
        handlers.append(onCommandCreated)

        cmdDef.execute()

        adsk.autoTerminate(False)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Tags (1)
4 REPLIES 4
Message 2 of 5
ekinsb
in reply to: nnikbin

Thank you for reporting this.  This was an oversight and we need to add a new property to the GroupCommandInput object to be able to get and set whether the check box is checked or not.  The existing isEnabled property does something similar but different.  You can see when it's true, then the group name is now gray in color and the group is not available.  All command inputs support the isEnabled property so the check box is something unique to the GroupCommandInput and needs a separate property to control it.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 5
nnikbin
in reply to: ekinsb

Hi Brian,

 

Thanks for your comprehensive answer. I think a problems in dedicating a separate property to the checked state of the checkbox will be the confusing name of isEnabledCheckBoxDisplayed. The name suggests that the checkbox is bound to isEnabled property.

 

I'm wondering what will be the negative point(s) of using isEnabled property as the checked state property? As you mentioned all command inputs support isEnabled property, but all of them can potentially have unique features when draw themselves in disabled state. So the GroupCommandInput who's isEnabledCheckBoxDisplayed is set to true can draw itself in enabled state with a checked checkbox and in disabled state with an unchecked checkbox. Is there any scenario that separating isEnabled property from the checked state of the checkbox benefit users or developers?

 

One answer to my question could be: "The user should not be able to control the enabled state of command inputs". But I think we only use GroupCommandInput with checkbox if we want to get the ability of controlling the enabled state of the group to users. Otherwise we can use simple GroupCommandInput.

 

In my Fracture add-in I need such GroupCommandInput for "Voronoi Level 2 Divisions" and "Explosion" group command inputs (as shown in the following screen captures). Currently I've used separate checkboxes for enabling and disabling related parameters.

 

Capture_08.png

 

Regards,

Navid

Message 4 of 5
ekinsb
in reply to: nnikbin

I don't disagree that setting a group as disabled probably isn't particularly useful, but because this property is inherited from the CommandInput base class I think it's best to be consistent in the behavior across all command inputs.  Typically where the isEnabled property would be used is if there are inputs that the user can't access yet because of various other states but you still want them to see and be aware that the setting exists.  For example, the Extrude command has an "Objects To Cut" input on the dialog but it's disabled when initially creating an extrude feature and is only enabled when editing an existing extrusions.  It could also be that you need to collect inputs in a certain order and you could control the order by disabling inputs until you're ready for them.

 

I agree with you that the name of the property is misleading.  isCheckBoxDisplayed would have been better.  We'll be adding a new isCheckBoxChecked property, probably in the end of October update.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 5
nnikbin
in reply to: ekinsb

Thanks! Totally agree with you. 

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