Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to call Command.doExecute() in one of my add-ins, but it makes Fusion crash.
Here is a small example created from the Fusion 360 examples.
I want to use doExecute() instead of just auto-executing, since doExecute() is blocking and can return a value.
#Author-
#Description-
import adsk.core, adsk.fusion, adsk.cam, traceback
_handlers = []
_ui = None
class MyCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
# Get the command that was created.
cmd = adsk.core.Command.cast(args.command)
onExecute = MyCommandExecuteHandler()
cmd.execute.add(onExecute)
_handlers.append(onExecute)
cmd.doExecute(True)
except:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
class MyCommandExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
# Get the command that was created.
cmd = adsk.core.Command.cast(args.command)
_ui.messageBox('Execute!')
except:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
global _ui
_ui = ui
#ui.messageBox('Hello addin')
# Get the existing command definition or create it if it doesn't already exist.
cmdDef = _ui.commandDefinitions.itemById('cmdInputsSample')
if not cmdDef:
cmdDef = _ui.commandDefinitions.addButtonDefinition('cmdInputsSample', 'Command Inputs Sample', 'Sample to demonstrate various command inputs.')
# Connect to the command created event.
onCommandCreated = MyCommandCreatedHandler()
cmdDef.commandCreated.add(onCommandCreated)
_handlers.append(onCommandCreated)
# Execute the command definition.
cmdDef.execute()
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()))
Solved! Go to Solution.