Clear dropdownlist Issues

Clear dropdownlist Issues

SeanKane88
Contributor Contributor
629 Views
1 Reply
Message 1 of 2

Clear dropdownlist Issues

SeanKane88
Contributor
Contributor

Hi,

 

I am starting my first fusion add-in and cannot get a dropdownlist to clear its contents.

 

I want to have a couple of dropdownlists, which dynamically update to reflect the user's selections. These dropdowns are:

 

1. A "section library" dropdown to choose from standard steel section libraries (i.e. hot rolled, welded, hollow etc.)

2. A "section type" dropdown to choose from more specific sections (i.e. square hollow, circular hollow)

3. A "section" dropdown to choose the specific section (i.e. "100x6 Square Hollow")

 

When the user changes their selections from a higher dropdown (1 or 2) the lower dropdowns should clear their contents and replace with the relevant options. However, I can't seem to get anything to work.

 

The following is the code I am using to try and clear the dropdowns:

 

                for i in range(0, sect.listItems.count):
                    sect.listItems.item(0).isSelected = False
                    sect.listItems.item(0).deleteMe()
                for i in range(0, secttype.listItems.count):
                    secttype.listItems.item(0).isSelected = False
                    secttype.listItems.item(0).deleteMe()

 

The following is a larger section of code from the InputChangedHandler. Note that the code for adding values to the dropdown lists works fine - i get ever expanding dropdown lists.

 

            if changedInput.id == 'sectlib':
                #if its the section library selection, update the section type box
                
                for i in range(0, sect.listItems.count):
                    sect.listItems.item(0).isSelected = False
                    sect.listItems.item(0).deleteMe()
                for i in range(0, secttype.listItems.count):
                    secttype.listItems.item(0).isSelected = False
                    secttype.listItems.item(0).deleteMe()

                lib = sectlib.selectedItem.name
                           
                if lib != '':
                    #next add the libraries to sectlib
                    
                    lines = readFile(getAddInFolder() + '\\Resources\\' + lib + '\\' + lib + '.txt')
                    if lines.count != 0:
                        for l in lines:
                            secttype.listItems.add(l,False)
                            
            elif changedInput.id == 'secttype':
                #need to add sections to the section dropdown                
                
                #ClearList(sect).
                for i in range(0, sect.listItems.count):
                    sect.listItems.item(0).isSelected = False
                    sect.listItems.item(0).deleteMe()                
                
                lib = sectlib.selectedItem.name
                styp = secttype.selectedItem.name  
                
                if lib !='' and styp !='':
                    lines = readFile(getAddInFolder()+'\\Resources\\' + lib + '\\' + styp + '\\' + styp + '.txt')
                    if lines.count != 0:
                        for l in lines:
                            sect.listItems.add(l, False)

 

0 Likes
630 Views
1 Reply
Reply (1)
Message 2 of 2

SeanKane88
Contributor
Contributor

I've found a work-around that isn't really a fix. The approach is:

 

1. When selection changes, add all the new items to the dropdown list

2. Make sure the selected item is one of the new items.

3. Delete all the original items from the start of the list.

 

This seems very kludgy to me so I'm not happy calling it a "solution" - a simple "clear list" method would be more appropriate.

 

Sample code:

 

            if changedInput.id == 'sectlib':
                #if its the section library selection, update the section type
                #and section boxes
                
                #need to add sections to the section dropdown first before
                #clearing out old sections as currently there is no "clear"
                # method for a dropdownlist                
                
                #get current no. items in each list
                sectN = sect.listItems.count
                secttypeN = secttype.listItems.count                
                
                #get library type
                lib = sectlib.selectedItem.name
                           
                if lib != '':
                    #next add the libraries to sectlib
                    
                    lines = readFile(getAddInFolder() + '\\Resources\\' + lib + '\\' + lib + '.txt')
                    if lines.count != 0:
                        for l in lines:
                            secttype.listItems.add(l,False)

                # if dropdown was already populated, clear original values 
                if secttypeN > 0:
                    #select a value outside original values
                    secttype.listItems.item(secttypeN).isSelected = True
                    
                    #get rid of everything in list except 1 selected value
                    for i in range(0, secttypeN):
                        secttype.listItems.item(0).deleteMe()
                
                #select the first new element
                secttype.listItems.item(0).isSelected = True                
                
                #add new sections to section list before clearing it.
                
                #get section type selected
                styp = secttype.selectedItem.name 
                
                #update the sect dropdown with new lines
                if lib !='' and styp !='':
                    lines = readFile(getAddInFolder()+'\\Resources\\' + lib + '\\' + styp + '.txt')
                    if lines.count != 0:
                        for l in lines:
                            sect.listItems.add(l, False)
                                   
                
                #select the first new element (i.e. 1 after old list)
                sect.listItems.item(sectN).isSelected = True                    
                
                #delete old list items
                for i in range(0, sectN):
                    sect.listItems.item(0).deleteMe()
                    
                #ensure first new item is selected
                sect.listItems.item(0).isSelected = True
                            
            elif changedInput.id == 'secttype':
                #if it's the section type selection, update the 'sect' dropdown                
                
                #need to add sections to the section dropdown first before
                #clearing out old sections as currently there is no "clear"
                # method for a dropdownlist
                
                #get current no. of items
                sectN = sect.listItems.count
                
                #get library and section type
                lib = sectlib.selectedItem.name
                styp = secttype.selectedItem.name  
                
                #add new elements
                if lib !='' and styp !='':
                    lines = readFile(getAddInFolder()+'\\Resources\\' + lib + '\\' + styp + '.txt')
                    if lines.count != 0:
                        for l in lines:
                            sect.listItems.add(l, False)
                            
                #select first element of new list items (i.e. 1 after old list)
                sect.listItems.item(sectN).isSelected = True

                #clear out original items.
                
                for i in range(0, sectN):
                    sect.listItems.item(0).deleteMe()                            

                #make sure first new item is selected
                sect.listItems.item(0).isSelected = True
0 Likes