Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Assign items in a list variable to a TextListDropDown

brad.bylls
Collaborator

Assign items in a list variable to a TextListDropDown

brad.bylls
Collaborator
Collaborator
I am creating a UI where the user picks an item from the first dropdown list.
That makes visible the second dropdown list and then reads a csv file and compare the two choices to create a selection for the third dropdown list.
The problem I am having is how to assign the list variable items to the dropdown list for the third TextListDropDown
It creates a list that looks like this:
getGLpin['2.25,
                 '2.75',
                 '3.75']
=======================================================================================
        # Define the command dialog.
        # Define Nominal Size dropdown box
        inputs.addImageCommandInput('glPinImage''''commands/resources/command_icons/SGP/SGP.png')
        _inputSelectNominalDiam = inputs.addDropDownCommandInput('nominalDiam''Nominal Diam', adsk.core.DropDownStyles.TextListDropDownStyle)
        _inputSelectNominalDiam.isVisible = True
        dropdown1Items = _inputSelectNominalDiam.listItems
        dropdown1Items.add('Pick Nominal Diameter'True'')
        dropdown1Items.add('3/4'False'')
        dropdown1Items.add('1'False'')
        dropdown1Items.add('1 1/4'False'')
        
        # Define Shoulder Length dropdown box
        _inputSelectShoulderLength = inputs.addDropDownCommandInput('shoulderLength''Shoulder Length', adsk.core.DropDownStyles.TextListDropDownStyle)
        _inputSelectShoulderLength.isVisible = False
        dropdown2Items = _inputSelectShoulderLength.listItems
        dropdown2Items.add('Pick Shoulder Length'True'')
        dropdown2Items.add('7/8'False'')
        dropdown2Items.add('1 3/8'False'')
        dropdown2Items.add('1 7/8'False'')
        
        # Define Pin Length dropdown box
        _inputSelectPinLength = inputs.addDropDownCommandInput('pinLength''Pin Length', adsk.core.DropDownStyles.TextListDropDownStyle)
        _inputSelectPinLength.isVisible = False
        dropdown3Items = _inputSelectPinLength.listItems
        dropdown3Items.add(getGLpin, False
 =====================================================================================
This is the code that creates the third list.

            getGLpin.clear
            filePath = os.path.dirname(os.path.realpath(__file__))
            fileCsv = open(filePath + '\\resources\\InchShoulderGuidePins.csv')
            for line in fileCsv:
                # Get the values from the csv file.
                glPinLength = line.split(',')

                if glPinLength[0] == strResult and glPinLength[1] == strResult1:
                    getGLpin.append(glPinLength[2])

            _inputSelectPinLength.isVisible = True              
 
Brad Bylls
1 Like
Reply
Accepted solutions (2)
467 Views
3 Replies
Replies (3)

BrianEkins
Mentor
Mentor
Accepted solution

The ListItems.add method expects a string as the first argument.  It looks like for the third drop down you're trying to use a list.  Instead, you need to iterate through the list and add a new list item for each string in the list.  Below is an example that does this assuming that getGLpin does return a list of strings.  

 

for  GLpin in getGLpin:
   dropdown3Items.add(GLpin, False)

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

brad.bylls
Collaborator
Collaborator

I understand now that a DropDownList is different than a list variable.

Here is the code in question:

shoulderLengths = []
            for sl in pinSpecs:
                if sl[0] == strResult and sl[1not in shoulderLengths:
                    shoulderLengths.append(sl[1])
                    dropdown2Items.add(sl[1], False'')
 
At first I got an error that said dropdowns2Items was not defined.
At the top of the code I put dropdown2Items = ' '
 
Now I get this error
Error.png
Brad Bylls
0 Likes

brad.bylls
Collaborator
Collaborator
Accepted solution

I figured it out.

I had to add 'dropdown3Items' to a list of global variables.

Brad Bylls
0 Likes