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: 

How to control ok button enable disable?

3 REPLIES 3
Reply
Message 1 of 4
obatake5TC3R
523 Views, 3 Replies

How to control ok button enable disable?

I do not search to control ok button in 'command' object. There are isOkButtonVisible or okButtonText propaty. But there are no control ok button.

Can I control ok button disable or enable?

3 REPLIES 3
Message 2 of 4
ekinsb
in reply to: obatake5TC3R

The validateInputs event allows you to control this.  In this event you can do whatever validation you need to determine if the needed input has been specified and if the OK button should be enabled.  The ValidateInputsEventArgs object that's passed in through the validateInputs event has the areInputsValid property.  If you set this to False, then the OK button will be disabled.

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 4
brad.bylls
in reply to: ekinsb

Is there simple code for this?

I just need to disable and enable the OK button.

Most of my input is through preloaded drop down boxes.

I know I can make the OK button invisible but can't make it visible again. Who'd a thought?

Thank you.

Brad Bylls
Message 4 of 4
kandennti
in reply to: brad.bylls

Hi @brad.bylls .

 

It is probably not possible to display the [OK] button in the middle of the process.

As described by @ekinsb , I think it is better to use the validateInputs event to control the [OK] button.

 

We have created a simple sample here.

When the number of selections is even, the OK button is enabled, and when the number is odd, it is disabled.

1.png

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

_commandId = 'ValidateInputsSample'
_SelIptId = 'selIpt'

_handlers = []
_app = None
_ui = None

class CommandDestroyHandler(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 ValidateInputsHandler(adsk.core.ValidateInputsEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        eventArgs = adsk.core.ValidateInputsEventArgs.cast(args)

        global _SelIptId
        selIpt = eventArgs.inputs.itemById(_SelIptId)
        if not selIpt:
            return

        if selIpt.selectionCount % 2 == 0:
            # OK button enabled
            eventArgs.areInputsValid = True
        else:
            # OK button disabled
            eventArgs.areInputsValid = False


class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            cmd = args.command

            # event
            global _handlers
            onDestroy = CommandDestroyHandler()
            cmd.destroy.add(onDestroy)
            _handlers.append(onDestroy)

            onValidateInputs = ValidateInputsHandler()
            cmd.validateInputs.add(onValidateInputs)
            _handlers.append(onValidateInputs)

            # inputs
            inputs = cmd.commandInputs

            global _SelIptId
            msg = 'Select an entity. \nThe OK button will be enabled only \nwhen the number of selections is even.'
            selIpt = inputs.addSelectionInput(_SelIptId, msg, msg)
            selIpt.setSelectionLimits(0)

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

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

        global _commandId
        cmdDefs = _ui.commandDefinitions
        cmdDef = cmdDefs.itemById(_commandId)
        if cmdDef:
            cmdDef.deleteMe()

        cmdDef = cmdDefs.addButtonDefinition(_commandId, _commandId, _commandId)

        onCmdCreated = CommandCreatedHandler()
        cmdDef.commandCreated.add(onCmdCreated)
        _handlers.append(onCmdCreated)
        cmdDef.execute()

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

No action will be taken when the OK button is pressed.

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