<?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 listItems refusing to reset selectedItem when cleared in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/listitems-refusing-to-reset-selecteditem-when-cleared/m-p/12343030#M2570</link>
    <description>&lt;P&gt;I have several inputs that use listItems (namely a Dropdown and a ButtonRow) in my plugin that need to update values depending on other inputs. Unfortunately, when I try to reset them, I can never get it to deselect the currently selected item. I've tried calling deleteMe(), setting isSelected=False, calling clear() on the parent listItems, and so forth, but the listItem.selectedItem is still there, and still valid too. Am I doing something wrong? Is this a known bug? What am I missing here?&lt;/P&gt;</description>
    <pubDate>Tue, 31 Oct 2023 10:37:29 GMT</pubDate>
    <dc:creator>perryK67ZX</dc:creator>
    <dc:date>2023-10-31T10:37:29Z</dc:date>
    <item>
      <title>listItems refusing to reset selectedItem when cleared</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/listitems-refusing-to-reset-selecteditem-when-cleared/m-p/12343030#M2570</link>
      <description>&lt;P&gt;I have several inputs that use listItems (namely a Dropdown and a ButtonRow) in my plugin that need to update values depending on other inputs. Unfortunately, when I try to reset them, I can never get it to deselect the currently selected item. I've tried calling deleteMe(), setting isSelected=False, calling clear() on the parent listItems, and so forth, but the listItem.selectedItem is still there, and still valid too. Am I doing something wrong? Is this a known bug? What am I missing here?&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 10:37:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/listitems-refusing-to-reset-selecteditem-when-cleared/m-p/12343030#M2570</guid>
      <dc:creator>perryK67ZX</dc:creator>
      <dc:date>2023-10-31T10:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: listItems refusing to reset selectedItem when cleared</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/listitems-refusing-to-reset-selecteditem-when-cleared/m-p/12348085#M2571</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14548705"&gt;@perryK67ZX&lt;/a&gt;&amp;nbsp;-San.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This has been my experience as well.&lt;/P&gt;
&lt;P&gt;It's not a pretty solution, but when I set up ListItems, I first assigned an item that means unselected and made it selected.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
import adsk
import adsk.core as core
import random

_app: core.Application = None
_ui: core.UserInterface = None
_handlers = []

CMD_INFO = {
    'id': 'kantoku_test',
    'name': 'test',
    'tooltip': 'test'
}

_dropIpt: core.DropDownCommandInput = None
_buttonIpt: core.BoolValueCommandInput = None

class MyCommandCreatedHandler(core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args: core.CommandCreatedEventArgs):
        core.Application.get().log(args.firingEvent.name)
        try:
            global _handlers
            cmd: core.Command = core.Command.cast(args.command)
            inputs: core.CommandInputs = cmd.commandInputs

            onDestroy = MyCommandDestroyHandler()
            cmd.destroy.add(onDestroy)
            _handlers.append(onDestroy)

            onInputChanged = MyInputChangedHandler()
            cmd.inputChanged.add(onInputChanged)
            _handlers.append(onInputChanged)

            global _buttonIpt
            _buttonIpt = inputs.addBoolValueInput(
                "_buttonIptId",
                "Change Items",
                False,
            )

            global _dropIpt
            _dropIpt = inputs.addDropDownCommandInput(
                "_dropIptId",
                "Select Item",
                core.DropDownStyles.TextListDropDownStyle,
            )
            reset_items(_dropIpt)

        except:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


class MyInputChangedHandler(core.InputChangedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args: core.InputChangedEventArgs):
        global _buttonIpt
        if args.input != _buttonIpt: return

        global _dropIpt
        reset_items(_dropIpt)


class MyCommandDestroyHandler(core.CommandEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args: core.CommandEventArgs):
        core.Application.get().log(args.firingEvent.name)
        adsk.terminate()


def reset_items(
        dropIpt: core.DropDownCommandInput
) -&amp;gt; None:
    listItems: core.ListItems = dropIpt.listItems
    listItems.clear()

    listItems.add("Plase Select Item", True)

    numbers = [random.randint(1, 100) for _ in range(5)]
    for num in numbers:
        listItems.add(str(num), False)


def run(context):
    try:
        global _app, _ui
        _app = core.Application.get()
        _ui = _app.userInterface

        cmdDef: core.CommandDefinition = _ui.commandDefinitions.itemById(
            CMD_INFO['id']
        )

        if not cmdDef:
            cmdDef = _ui.commandDefinitions.addButtonDefinition(
                CMD_INFO['id'],
                CMD_INFO['name'],
                CMD_INFO['tooltip']
            )

        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()))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;When I click on the "Change Items" button, the drop-down list changes and the "Plase Select Item" becomes selected.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 299px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1287255i0BD9C159AB25D551/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 01:41:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/listitems-refusing-to-reset-selecteditem-when-cleared/m-p/12348085#M2571</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2023-11-02T01:41:56Z</dc:date>
    </item>
  </channel>
</rss>

