Save selected dropdown item in class item

Save selected dropdown item in class item

Anonymous
Not applicable
648 Views
3 Replies
Message 1 of 4

Save selected dropdown item in class item

Anonymous
Not applicable

Dear Fusion-Community

 

For my semesterthesis I am creating an automated order tool for additive manufacturing parts directly out of Fusion. Therefore, I implemented a user-interface where the designer can select the body in Fusion and then he can choose from own defined properties like material, finishing, supplier etc from a dropdown list.

 

After having all properties selected, I want to save all selected properties in a class. Therefore I used "Bolt" sample code and changed it accordingly. Since I use other CommandInputs (like dropdownlists) than in the sample, I struggle with saving the selected item of the drowdown list in the right data format. The output of code used below (input.selectedItem) is "<adsk.core.ListItem; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::core::ListItem > *' at 0x14f6906f0> >", but I want to have the value of the selected item.

Many thanks in advance for your support!

Daniel

 

 

class OrderCommandExecuteHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            #unitsMgr = app.activeProduct.unitsManager
            command = args.firingEvent.sender
            inputs = command.commandInputs

            order = Order()
            for input in inputs:
                #print(input.name)
                if input.id == 'orderName':
                    order.orderName = input.value
                    print(order.orderName)
                elif input.id == 'Quotation':
                    order.Quotation = input.text
                    print(order.Quotation)
                elif input.id == 'Anzahl':
                    order.Anzahl = input.valueOne
                    print(order.Anzahl)
                elif input.id == 'Material':
                    order.Material = input.selectedItem
                    print(order.Material)
                elif input.id == 'Prozess':
                    order.Prozess = input.selectedItem
                    print(order.Prozess)
                elif input.id == 'Ausrichtung':
                    order.Ausrichtung = input.text
                    print(order.Ausrichtung)
                elif input.id == 'Oberflaeche':
                    order.Oberflaeche = input.selectedItem
                    print(order.Oberflaeche)
                elif input.id == 'Farbe':
                    order.Farbe = input.selectedItem
                    print(order.Farbe)
                elif input.id == 'Typ':
                    order.Typ = input.selectedItem
                    print(order.Typ)
                elif input.id == 'Projekt':
                    order.Projekt = input.selectedItem
                    print(order.Projekt)
                elif input.id == 'KTI':
                    order.KTI = input.value
                    print(order.KTI)
                elif input.id == 'Lieferant':
                    order.Lieferant = input.selectedItem
                    print(order.Lieferant)
                elif input.id == 'Versanddatum':
                    order.Versanddatum = input.text
                    print(order.Versanddatum)
0 Likes
649 Views
3 Replies
Replies (3)
Message 2 of 4

BrianEkins
Mentor
Mentor

The DropDownCommandInput object supports the "selectedItem" property, which you are already using.  This property returns a ListItem object.  The ListItem object supports the "name" property, which will return the string that you see in the drop-down.  I think that's what you want.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks a lot for your answer!

 

It worked like this:


                elif input.id == 'commandId':
                    for element in input.listItems:
                         if element.isSelected:
                             dropdown_selection = element.name
0 Likes
Message 4 of 4

Anonymous
Not applicable

Thanks a lot for your answer!

 

It worked like this:


                elif input.id == 'commandId':
                    for element in input.listItems:
                         if element.isSelected:
                             dropdown_selection = element.name
0 Likes