How to delete rows in DropdownCommandInput

How to delete rows in DropdownCommandInput

Anonymous
Not applicable
1,277 Views
12 Replies
Message 1 of 13

How to delete rows in DropdownCommandInput

Anonymous
Not applicable

Hello. It need delete rows in DropDownCommandInput if button delete is pressed. I try this code

dropDownCommandInput=adsk.core.DropDownCommandInput.cast(inputs.itemById(piecesListId))
    if dropDownCommandInput:
        for item in dropDownCommandInput.listItems:            
            item.deleteMe

I try delete all rows and add new rows, but only new rows are added.How delete all rows in DropDownCommandInput?

0 Likes
1,278 Views
12 Replies
Replies (12)
Message 2 of 13

ekinsb
Alumni
Alumni

You've gotten caught by a common Python programming error that I've made several times myself.

 

item.deleteMe

 

should be

 

item.deleteMe()

 

Your current code is just getting a reference to the deleteMe function while the second one is executing it.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 13

Anonymous
Not applicable

Sorry it was my mistake. I try this code, but one row still remain.

    dropDownCommandInput=adsk.core.DropDownCommandInput.cast(inputs.itemById(piecesListId))
    dropdownItems=dropDownCommandInput.listItems
    count=dropDownCommandInput.listItems.count
    index=count-1
    while index>=0:          
        row=dropDownCommandInput.listItems.item(index)
        print(row.deleteMe())
        index-=1

row.deleteMe() return False if index=0

how to remove last Row?

0 Likes
Message 4 of 13

ekinsb
Alumni
Alumni

I'm not exactly sure why your code isn't working.  I didn't take the time to debug it, but this simpler version is working for me.

 

    dropDown = eventArgs.inputs.itemById('dropDown')
for i in range(0, dropDown.listItems.count):
print(dropDown.listItems.item(0).deleteMe())

 

We also have it on our backlog to add a "clear" method to the ListItems class to make this much easier.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 5 of 13

Anonymous
Not applicable
dropDownCommandInput = inputs.itemById(piecesListId) 
    for i in range(0, dropDownCommandInput.listItems.count): 
        print(dropDownCommandInput.listItems.item(0).deleteMe())

print False( , and no one row is not delete.

 

but if add Breakpoint and write in console 

dropDownCommandInput.listItems.item(1).deleteMe()

return true 

0 Likes
Message 6 of 13

ekinsb
Alumni
Alumni

I don't know what the difference could be.  I just double-checked my test and it's returning True for every delete.  What type of drop-down are you testing with?  I'm using check boxes.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 7 of 13

Anonymous
Not applicable

commandInputs_.addDropDownCommandInput(piecesListId, 'Piece', adsk.core.DropDownStyles.TextListDropDownStyle);

0 Likes
Message 8 of 13

Anonymous
Not applicable

Active Row is not deleted. It need delete all old rows and set new list of rows.

0 Likes
Message 9 of 13

ekinsb
Alumni
Alumni

I've verified the problem with a text list and also see that it's not allowing the selected item in the list to be deleted.  The only workaround I can see now is:

 

1. Delete all of the items in the list except for the selected item.

2. Add your new items to the list and have one them selected.

3. Delete the first item in the (which will be the one left over).


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 10 of 13

Anonymous
Not applicable

No chanses :), I am crying. When in list remains 2 rows. Both rows have status isSelected=True, and no one is not deletable

 

 

def deleteSelectedRow(inputs):
    dropDownCommandInput=adsk.core.DropDownCommandInput.cast(inputs.itemById(piecesListId))
    count =  len(dropDownCommandInput.listItems)
    first=True
    
    for piece in currentPiecesSet.pieces:

        if first==True:
            dropDownCommandInput.listItems.add(piece.name, False, '')
            first=False
        else: dropDownCommandInput.listItems.add(piece.name, False, '')
    dropDownCommandInput.listItems.item(1).isSelected=True
    
    for i in range(0, count): 

        dropDownCommandInput.listItems.item(1).isSelected=True
        dropDownCommandInput.listItems.item(0).deleteMe()
        
    print(len(dropDownCommandInput.listItems))
    

 

0 Likes
Message 11 of 13

Anonymous
Not applicable

code without garbage

def deleteSelectedRow(inputs):
    dropDownCommandInput=adsk.core.DropDownCommandInput.cast(inputs.itemById(piecesListId))
    count =  len(dropDownCommandInput.listItems)
 
    for piece in currentPiecesSet.pieces:
            dropDownCommandInput.listItems.add(piece.name, True, '')
    
    for i in range(0, count): 

        dropDownCommandInput.listItems.item(1).isSelected=True
        dropDownCommandInput.listItems.item(0).deleteMe()
        
    print(len(dropDownCommandInput.listItems))
0 Likes
Message 12 of 13

Anonymous
Not applicable
It looks like a Bug, or I am not right?
0 Likes
Message 13 of 13

SeanKane88
Contributor
Contributor

Has this issue been fixed or a solution found? I am having exactly the same problem.

0 Likes