Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to detect when some preexisting (native) commands are created, and is not working. It works just fine if it is my own custom command.
import adsk.core, adsk.fusion, adsk.cam, traceback, logging, sys _app = None _ui = None _handlers = [] logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) class CamCommandCreatedHandler(adsk.core.CommandCreatedEventHandler): def __init__(self): super().__init__() def notify(self, args): # Never get here if the command is native global _app, _ui try: eventArgs = adsk.core.CommandCreatedEventArgs.cast(args) cmd = eventArgs.command cmdDef = cmd.parentCommandDefinition if _ui: _ui.messageBox('CamCommandCreatedHandler; Id: {0}; Command: {1}'.format(cmdDef.id, cmd.objectType)) except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) def run(context): global _app, _ui _app = adsk.core.Application.get() _ui = _app.userInterface try: logging.debug('Starting') onCommandCreated = CamCommandCreatedHandler() _handlers.append(onCommandCreated) cmdDefs = _ui.commandDefinitions cmdDef = cmdDefs.itemById('cmdMyCustomCommand') if cmdDef: cmdDef.deleteMe() for i in range(0, cmdDefs.count): cmdDef = cmdDefs.item(i) logging.debug('Name: {0}; Native: {1}; Id: {2}'.format(cmdDef.name, cmdDef.isNative, cmdDef.id)) cmdDef = cmdDefs.itemById('IronStrategy_face') # vs: cmdDefs.addButtonDefinition('cmdMyCustomCommand','My Custom Command', '', '') handlerAdded = cmdDef.commandCreated.add(onCommandCreated) logging.debug('Name: {0}; Native: {1}; Id: {2}; CommandCreatedEvent: {3}'.format(cmdDef.name, cmdDef.isNative, cmdDef.id, handlerAdded)) cmdDef.execute() adsk.autoTerminate(False) except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) def stop(context): global _app, _ui try: logging.debug('Stopping') except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
My end goal is to add some custom UI elements to some native (CAM) commands' input, if there is a better method than injecting into each command's create event.
Solved! Go to Solution.