ShelfButton with Dynamic Popup Breaks on Maya Restart
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I wonder if any UI gurus can help me out...
I've created a maya shelf button in mel and attached a popup menu to it. The popupMenu uses the postMenuCommand flag to run a method that dynamically adds menu items to the popup.
Broadly it looks like the code below.
This all works well until I restart Maya. At that point maya saves the shelves to prefs and as it does this it only saves information about the buttons and the currently active popup entries. The link to the dynamic is lost. When maya restarts again the shelf button appears with a fixed list of whatever menuItems appeared in the list when it was closed.
I'd like it to not do this but so far I've only been able to get close to what I want by creating my own versions of the the built in mel scripts loadNewShelf, addNewShelfTab and deleteShelfTab. Which seems excessive and means I have to provide my own auto load mechanism for this shelf, instead of allowing users to just load it via the maya interface.
Thanks!
## MEL shelf file
global proc shelf_my_shelf () {
global string $gBuffStr;
global string $gBuffStr0;
global string $gBuffStr1;
...
shelfButton
...
-command "import python_widget; python_widget.open()"
-sourceType "python"
-noDefaultPopup
"my_shelf_button"
;
python("import shelf_helpers; shelf_helpers.setup_menus()");
}
## shelf_helpers.py
# Create the popup menu
def setup_menus():
cmds.popupMenu(
"shelf_popup_menu",
p="my_shelf_button",
b=3,
pmc="shelf_helpers.update_recent_file_menu()"
)
# update the popup with our dynamic data
def update_recent_file_menu():
data_list = get_data()
popup_menu = cmds.popupMenu("shelf_popup_menu", e= True, deleteAllItems=True)
cmds.menuItem(
p="shelf_popup_menu",
d=True,
dl="Pick Option..."
)
for each in data:
cmds.menuItem(
p="shelf_popup_menu",
l=data
)