- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm writing a logger plugin to write UI interactions to a text file. To get fine-grained information, I'd like to include the values that the user enters in native Commands such as extrusion values etc. However, in order to get access to the Command object to define the appropriate listeners such as KeyboardEvents, I need to listen for the CommandCreatedEvent on the native CommandDefinitions. The code below does exactly that (and returns True for every .add() call). However, the notify function in the CommandCreatedHandler is never triggered.
Any help or input would be greatly appreciated.
import adsk.core, adsk.fusion, adsk.cam, traceback
handlers = []
def run(context):
ui = adsk.core.Application.get().userInterface
try:
for i in range(ui.commandDefinitions.count):
command_definition = ui.commandDefinitions.item(i)
onCommandCreated = CommandCreatedHandler(print_text)
success = command_definition.commandCreated.add(onCommandCreated) #success is true in every iteration.
handlers.append(onCommandCreated)
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()))
class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self, callback):
super().__init__()
def notify(self, args): #this is never triggered
eventArgs = adsk.core.CommandCreatedEventArgs(args)
command = eventArgs.command #this is what I need for defining the listeners
adsk.core.Application.get().userInterface.messageBox("TEST")
According to the documentation, the above should be possible:
Any command (standard Fusion 360 or API created commands) can be run by the user clicking a button or by a program calling the command definitions execute method. In either case, Fusion 360 creates a new Command object and fires the commandCreated event where it passes the Command object to your add-in. Your add-in reacts to this event by connecting to other command related events and defining the contents of the command dialog, if it has one.
Solved! Go to Solution.