<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Accessing The Drop Down List selected Item from Input Changed Handler in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/accessing-the-drop-down-list-selected-item-from-input-changed/m-p/8371349#M20063</link>
    <description>&lt;P&gt;In the original example you could simplify the code:&lt;/P&gt;
&lt;PRE&gt;                        objectItems = cmdInput.listItems
                        selection = None
                        for item in objectItems:
                            ui.messageBox(str(item.name)+"selected = "+str(item.isSelected))
                            if item.isSelected:
                                selection = item
                                break&lt;/PRE&gt;
&lt;P&gt;to be:&lt;/P&gt;
&lt;PRE&gt;objectItems = cmdInput.selectedItem&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;This is from the reference here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-d48e4975-f1c0-494f-b2aa-d41c20532009" target="_blank"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-d48e4975-f1c0-494f-b2aa-d41c20532009&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Oct 2018 15:05:51 GMT</pubDate>
    <dc:creator>luke.edwards.autodesk</dc:creator>
    <dc:date>2018-10-31T15:05:51Z</dc:date>
    <item>
      <title>Accessing The Drop Down List selected Item from Input Changed Handler</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/accessing-the-drop-down-list-selected-item-from-input-changed/m-p/6268724#M20060</link>
      <description>&lt;P&gt;I'm trying to access a selected item from a Text Drop down text box and use that as a key to a dictionary that will influence the input types I fill a second tab with.&lt;/P&gt;&lt;P&gt;However no item seems to be selected even though there was a change that activated the handler. How do I access the selected item in this list? Is it possible or are there work arounds?&lt;/P&gt;&lt;P&gt;Here are the handlers in m&lt;/P&gt;&lt;PRE&gt;class InputChangedHandler(adsk.core.InputChangedEventHandler):
            def __init__(self):
                super().__init__()
            def notify(self, args):
                try:
                    command = args.firingEvent.sender
                    cmdInput = args.input
                    if cmdInput.id == 'ObjectTypeSelection':
                        ui.messageBox('Input: {} changed event triggered for Object Selection'.format(command.parentCommandDefinition.id))
                        inputs = command.commandInputs
                        ui.messageBox("Input is valid: "+str(cmdInput.isValid))
                        objectItems = cmdInput.listItems
                        selection = None
                        for item in objectItems:
                            ui.messageBox(str(item.name)+"selected = "+str(item.isSelected))
                            if item.isSelected:
                                selection = item
                                break
                        ui.messageBox("selection: "+str(selection))
                        tabCmdInput2 = inputs.addTabCommandInput(commandIdOnPanel + '_tab_2', 'Define your ')
#                        tab1ChildInputs = tabCmdInput2.children
                except:
                    if ui:
                        ui.messageBox('Input changed event failed: {}'.format(traceback.format_exc()))

        class CommandExecuteHandler(adsk.core.CommandEventHandler):
            def __init__(self):
                super().__init__()
            def notify(self, args):
                try:
                    command = args.firingEvent.sender
                    ui.messageBox('command: {} executed successfully'.format(command.parentCommandDefinition.id))
                except:
                    if ui:
                        ui.messageBox('command executed failed: {}'.format(traceback.format_exc()))

        class CommandCreatedEventHandlerPanel(adsk.core.CommandCreatedEventHandler):
            def __init__(self):
                super().__init__() 
            def notify(self, args):
                try:
                    cmd = args.command
                    onExecute = CommandExecuteHandler()
                    cmd.execute.add(onExecute)

                    onInputChanged = InputChangedHandler()
                    cmd.inputChanged.add(onInputChanged)
                    # keep the handler referenced beyond this function
                    handlers.append(onExecute)
                    handlers.append(onInputChanged)
                    # Keep the handler referenced beyond this function
                    inputs = cmd.commandInputs
        
                    # Create tab input 1
                    tabCmdInput1 = inputs.addTabCommandInput(commandIdOnPanel + '_tab_1', 'Object Type Selection')
                    tab1ChildInputs = tabCmdInput1.children
                    dropDownCommandInput = tab1ChildInputs.addDropDownCommandInput('ObjectTypeSelection', 'Select an Object Definition', adsk.core.DropDownStyles.TextListDropDownStyle)
                    dropDownItems = dropDownCommandInput.listItems
                    for objType in {"Bolt":"stuff"}:
                        dropDownItems.add(objType, False)                    
                    ui.messageBox('Panel command created successfully')
                except:
                    if ui:
                        ui.messageBox('Panel command created failed: {}'.format(traceback.format_exc()))&lt;/PRE&gt;&lt;P&gt;y code. Bolt should be shown as selected.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 15:57:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/accessing-the-drop-down-list-selected-item-from-input-changed/m-p/6268724#M20060</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-04-13T15:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing The Drop Down List selected Item from Input Changed Handler</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/accessing-the-drop-down-list-selected-item-from-input-changed/m-p/6269510#M20061</link>
      <description>&lt;P&gt;It took a little while, but I've discovered the problem.&amp;nbsp; There is a bug in the API, but there is also a simple workaround.&amp;nbsp; The problem occurs when you create a drop down without any of the items being selected.&amp;nbsp; The first time an item is selected from the drop down Fusion doesn't correctly return the selected item.&amp;nbsp; However, if there is an item already selected then everything works as expected.&amp;nbsp; If you don't want to have an item selected because the act of selecting one causes an action, you can add an additional item that is something like "None" or even have an item that is an empty string.&amp;nbsp; You can put the empty string item at the bottom of the list so it's not as obvious that it's there.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think any of the Fusion commands use a drop down in this way so it's possibly wasn't designed to support not having any of the items selected.&amp;nbsp; I'll log a bug but it's not obvious right now what the "correct" answer will be to fix it.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 21:14:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/accessing-the-drop-down-list-selected-item-from-input-changed/m-p/6269510#M20061</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2016-04-13T21:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing The Drop Down List selected Item from Input Changed Handler</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/accessing-the-drop-down-list-selected-item-from-input-changed/m-p/6334616#M20062</link>
      <description>&lt;P&gt;This will be fixed in our May 25 update!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2016 17:13:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/accessing-the-drop-down-list-selected-item-from-input-changed/m-p/6334616#M20062</guid>
      <dc:creator>keqingsong</dc:creator>
      <dc:date>2016-05-18T17:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing The Drop Down List selected Item from Input Changed Handler</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/accessing-the-drop-down-list-selected-item-from-input-changed/m-p/8371349#M20063</link>
      <description>&lt;P&gt;In the original example you could simplify the code:&lt;/P&gt;
&lt;PRE&gt;                        objectItems = cmdInput.listItems
                        selection = None
                        for item in objectItems:
                            ui.messageBox(str(item.name)+"selected = "+str(item.isSelected))
                            if item.isSelected:
                                selection = item
                                break&lt;/PRE&gt;
&lt;P&gt;to be:&lt;/P&gt;
&lt;PRE&gt;objectItems = cmdInput.selectedItem&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;This is from the reference here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-d48e4975-f1c0-494f-b2aa-d41c20532009" target="_blank"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-d48e4975-f1c0-494f-b2aa-d41c20532009&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Oct 2018 15:05:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/accessing-the-drop-down-list-selected-item-from-input-changed/m-p/8371349#M20063</guid>
      <dc:creator>luke.edwards.autodesk</dc:creator>
      <dc:date>2018-10-31T15:05:51Z</dc:date>
    </item>
  </channel>
</rss>

