Hi @JanNavratil .
It is necessary to implement what is described in Help.
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-2ACFFC2F-458B-4740-93B8-CCC56638D8AA
I made a simple Select Event sample.
I think you will need a code that is at least this long.
#Fusion360API Python script
#Author-kantoku
#Description-Select Event Sample
import adsk.core, adsk.fusion, traceback
_commandId = 'SelectionEvent'
_SelIpt1ID = 'Selectioninput1'
_handlers = []
_app = None
_ui = None
class CommandDestroyHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
adsk.terminate()
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Event handler for the select event.
# https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-2ACFFC2F-458B-4740-93B8-CCC56638D8AA
class MySelectHandler(adsk.core.SelectionEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
eventArgs = adsk.core.SelectionEventArgs.cast(args)
# Code to react to the event.
_ui.messageBox('In MySelectHandler event handler.')
class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
cmd :adsk.core.Command = args.command
onDestroy = CommandDestroyHandler()
cmd.destroy.add(onDestroy)
_handlers.append(onDestroy)
onSelect = MySelectHandler()
cmd.select.add(onSelect)
_handlers.append(onSelect)
inputs = cmd.commandInputs
i1 = inputs.addSelectionInput(_SelIpt1ID, _SelIpt1ID, _SelIpt1ID)
i1.setSelectionLimits(0)
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def run(context):
try:
global _app, _ui
_app = adsk.core.Application.get()
_ui = _app.userInterface
cmdDefs = _ui.commandDefinitions
cmdDef = cmdDefs.itemById(_commandId)
if cmdDef:
cmdDef.deleteMe()
cmdDef = cmdDefs.addButtonDefinition(_commandId, _commandId, _commandId)
onCmdCreated = CommandCreatedHandler()
cmdDef.commandCreated.add(onCmdCreated)
_handlers.append(onCmdCreated)
cmdDef.execute()
adsk.autoTerminate(False)
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))