Register Latest Topics
 
 
 


Reply
  Author   Comment  
Unai

First taste
Registered:
Posts: 10
Reply with quote  #1 
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?

Thanks!
0
pshipkov

SOuP Jedi
Registered:
Posts: 4,732
Reply with quote  #2 
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.
0
Unai

First taste
Registered:
Posts: 10
Reply with quote  #3 
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.
0
pshipkov

SOuP Jedi
Registered:
Posts: 4,732
Reply with quote  #4 
The MEL way:

int $i;
window;
columnLayout;
button;
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
setParent;
showWindow;

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



the Python way:

i = 0

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

import maya.cmds as mc
mc.window()
mc.columnLayout()
mc.button()
mc.popupMenu(b=1, pmc=updateMenuItems)
mc.setParent("..")
mc.showWindow()

Every time you click on the button you will see that the old menuItem have been deleted and replaced with new one.
0
Unai

First taste
Registered:
Posts: 10
Reply with quote  #5 
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
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.