Hiding the Cancel button on a command ui but isCancelButtonVisible has no effect

Hiding the Cancel button on a command ui but isCancelButtonVisible has no effect

Anonymous
Not applicable
733 Views
2 Replies
Message 1 of 3

Hiding the Cancel button on a command ui but isCancelButtonVisible has no effect

Anonymous
Not applicable

I have a simple command setup and it launches a UI dialogue with some simple controls. It is the type of thing that a cancel button would serve no use, so I'd like to hide it and change the OK button to say "Close". I read in the documentation for Command object that:

 

cancelButtonTextGets and sets the text displayed on the Cancel button. The value of this property is ignored if the isCancelButtonVisible property is false.

 

However setting the isCancelButtonVisible to False has no effect. I noticed there is no documentation for this property either... was this just missed in the development process? Are there any alternative ways to hide the cancel button? Any help would be greatly appreciated.

 

I am using python, and I am able to change the text using this property or even hide the OK button using isOKButtonVisible. I would use the cancel button to close it but the cancel button doesn't execute the command.

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

kandennti
Mentor
Mentor
Accepted solution

Hi @Anonymous .

 

Although it is described in Help, it seems that the Command object does not have the isCancelButtonVisible property.
Probably, it is not supposed to use the dialog without the Cancel button.

I don't know if it's a good way to go, but it seems to do what you want.
・Command.isOKButtonVisible = False
・Command.cancelButtonText = 'OK'
・Describe the desired processing in the CommandDestroy event.
 
#FusionAPI_python_script
import adsk.core, adsk.fusion, traceback

_app = None
_ui  = None
_handlers = []

class MyCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            cmd = adsk.core.Command.cast(args.command)
            inputs = cmd.commandInputs
            
            onDestroy = MyCommandDestroyHandler()
            cmd.destroy.add(onDestroy)
            _handlers.append(onDestroy)

            inputs.addTextBoxCommandInput('test', 'test', 'test', 1, True)

            # hide OK Button
            cmd.isOKButtonVisible = False

            # rename Cancel Button
            cmd.cancelButtonText = 'OK'
        except:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class MyCommandDestroyHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            # Perform the process you want to call here
            _ui.messageBox('Call Destroy Event')

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

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

        cmdDef = _ui.commandDefinitions.itemById('test')
        if cmdDef:
            cmdDef.deleteMe()
        
        cmdDef = _ui.commandDefinitions.addButtonDefinition('test', 'test', 'test')

        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()))
Message 3 of 3

Anonymous
Not applicable

Thank you so much the 

 

command.destroy.add(onExecute)

 

 was the missing piece I didn't know existed. All works perfectly!

 

P.S. Sorry for the late response took a break from this for a bit.

0 Likes