C#ATIA

↑タイトル詐欺 主にFusion360API 偶にCATIA V5 VBA(絶賛ネタ切れ中)

ドロップダウンを選択するとメッセージを表示する

質問に対してサンプルを作ったのですが、他の方が先に答えてしまい、
行き場を失った為こちらに投げておきます。
Fusion Python Script - Create Multi Selection Panel - Autodesk Community

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

_app: adsk.core.Application = None
_ui: adsk.core.UserInterface = None
_handlers = []

class MyInputChangedHandler(adsk.core.InputChangedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args: adsk.core.InputChangedEventArgs):

        if args.input.id != 'dropdown':
            return

        selectName = args.input.selectedItem.name
        if selectName == 'Selection1':
            selection1()
        if selectName == 'Selection2':
            selection2()
        if selectName == 'Selection3':
            selection3()
        if selectName == 'Selection4':
            selection4()


def selection1():
    global _ui
    _ui.messageBox("Selection1 Selected", 'Fusion 360', 0, 3)

def selection2():
    global _ui
    _ui.messageBox("Selection2 Selected", 'Fusion 360', 0, 3)

def selection3():
    global _ui
    _ui.messageBox("Selection3 Selected", 'Fusion 360', 0, 3)

def selection4():
    global _ui
    _ui.messageBox("Selection4 Selected", 'Fusion 360', 0, 3)


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)

            onInputChanged = MyInputChangedHandler()
            cmd.inputChanged.add(onInputChanged)
            _handlers.append(onInputChanged)

            dropdownIpt = inputs.addDropDownCommandInput(
                'dropdown',
                'Dropdown',
                adsk.core.DropDownStyles.LabeledIconDropDownStyle
            )
            dropdownItems = dropdownIpt.listItems
            dropdownItems.add('Selection1', False, '')
            dropdownItems.add('Selection2', False, '')
            dropdownItems.add('Selection3', False, '')
            dropdownItems.add('Selection4', False, '')
        except:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


class MyExecuteHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args):
        adsk.core.Application.get().log('Call Execute Event')


class MyCommandDestroyHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args):
        adsk.core.Application.get().log('Call Destroy Event')
        adsk.terminate()


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()))

質問者さんの例を忠実にサンプル化したので、結構雑な処理です。