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: 

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

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
emkreloff
349 Views, 2 Replies

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

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.

2 REPLIES 2
Message 2 of 3
kandennti
in reply to: emkreloff

Hi @emkreloff .

 

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
emkreloff
in reply to: kandennti

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.

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