I’m a big fan of how the SOuP shelf buttons work, and I want to do something similar. The catch is, in my example, the popupMenu would need to be generated each time the button is clicked.

Does anyone have an idea on how to achieve this?

Quote 0 0
It goes something like that:

on-click, get attached popupMenu (there is a flag for that in query mode).
delete popupMenu - this will remove all menuItems attached to it.
create new popupMenu and add menuItems under it

You can keep the popupMenu and only manage menuItems under it. Either way will be fine.
Quote 0 0
Cool, thanks a bunch!

How would you go about actually showing that menu when clicked? Right now I assign the popupMenu to button 1 (left), so the first time I click the button the code runs and creates the menu, and the 2nd time, the menu shows up and the code never gets ran again, so I can’t delete it and recreate it :/

The ideal behaviour on click would be to delete, generate, and show. I can’t do the “show” bit, which breaks it all.
Quote 0 0
The MEL way:

int $i;
popupMenu -b 1 -pmc "updateMenuItems(\"#1\")"; // the #1 string passes to the function the name of the newly created popupMenu widget - a standard MEL thing

proc updateMenuItems(string $popupMenu)
    global int $i;
    popupMenu -e -dai $popupMenu;
    menuItem -l ("menuItem_"+(string)$i);

the Python way:

i = 0

def updateMenuItems(*arg):
    global i
    mc.popupMenu(arg[0], e=True, dai=True)
    i += 1

import maya.cmds as mc
mc.popupMenu(b=1, pmc=updateMenuItems)

Every time you click on the button you will see that the old menuItem have been deleted and replaced with new one.
Quote 0 0
Thank you so much! With your help, I’ve made a shelf button that almost behaves like the SOuP ones. Since the popupMenu is generated upon calling its script, I still have to click twice the first time to make it pop up, but other than that it works like a charm! :D
Quote 0 0

Add a Website Forum to your website.