Change dropdown box contents


#1

I have this following bit of code, but I’d like to change the dropdown box contents using a function. I’d like it to initially have nothing (so get rid of the frames = [] bit), and have it display the correct frames relating to something else, when you select that something else.


                                    with pm.rowColumnLayout(numberOfColumns=5):
                                        pm.radioCollection()
                                        pm.radioButton(label='Absolute')
                                        with pm.rowColumnLayout(numberOfColumns=2): 
                                            pm.radioButton(label='Relative to', select=True)
                                            pm.optionMenu(label='')
                                            pm.menuItem(label='Current Location')
                                            frames = ['frame1', 'frame2', 'frame3']
                                            for frame in frames:
                                                pm.menuItem(label=frame)
                                        pm.text(label='')
                                        pm.text(label='')
                                        pm.text(label='')

Usually, I’d do something like this:


    #main UI
    self.some_text = pm.textField(text='something')

    #function
    pm.textField(self.some_text, edit=True, text='something else')

But here, the menuItems are separate objects. How would I go about changing the labels, and adding/removing them if needed?


#2

You can remove all items and rebuild them. Just list them with itemLongList and use a deleteUI() to remove them. Then you can rebuild them if you use the -parent flag:

yourOptionMenu = pm.optionMenu(...)
labels = optionMenu(yourOptionMenu, q=True, itemListLong=True)
pm.deleteUI(labels)

menuItem(label="someLabel", parent=youOptionMenu)