Hi @Anonymous .
Probably the isCancelButtonVisible property does not exist.
When I tried it, the destroy event was called by both the OK and Cancel buttons.
In order to determine which button was pressed, I prepared a variable with a large scope and tried to determine whether the Execute event was called or not.
# Fusion360API Python Addin
import adsk.core, adsk.fusion, traceback
_app = None
_ui = None
_handlers = []
_isSelectedCancel = True #Record that the Cancel button was pressed.
class MyCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
global _handlers
cmd = adsk.core.Command.cast(args.command)
inputs = cmd.commandInputs
onDestroy = MyCommandDestroyHandler()
cmd.destroy.add(onDestroy)
_handlers.append(onDestroy)
onExecute = MyExecuteHandler()
cmd.execute.add(onExecute)
_handlers.append(onExecute)
inputs.addTextBoxCommandInput('test', 'test', '-', 1, True)
except:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
class MyExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
dumpMsg('Call Execute Event')
global _isSelectedCancel
_isSelectedCancel = False
class MyCommandDestroyHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
dumpMsg('Call Destroy Event')
global _ui, _isSelectedCancel
msg = 'Cancel' if _isSelectedCancel else 'OK'
_ui.messageBox(f'Selected {msg} Button')
def run(context):
try:
global _app, _ui
_app = adsk.core.Application.get()
_ui = _app.userInterface
cmdDef = _ui.commandDefinitions.itemById('Test')
if not cmdDef:
cmdDef = _ui.commandDefinitions.addButtonDefinition('Test', 'Test', 'Test')
global _handlers
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()))
def stop(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
ui.messageBox('Stop addin')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def dumpMsg(msg :str):
adsk.core.Application.get().userInterface.palettes.itemById('TextCommands').writeText(str(msg))
I don't know the content, but if you use the executePreview event, you may not need to clean up.
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-dbecfaf8-9bb6-4e40-9df3-0a3e48136a4b