Hello, I am having a slight issue and was hoping someone could help me out. I’m trying to have a textField where if the user right clicks the field a popupMenu will show revealing several menuItems attached and if the user selects any of the menu items a string is inputted into the textField. My issue is that no matter the menuItem being clicked it always returns the same string into the textField but I want it to return the string that is designated for the proper menuItem. I think my problem is because I am querying the command but im not sure what else to query to see if the menuItem has been selected, I appreciate any advice.
You cannot query the command of a UI control in Maya, the result will always be None.
I would either create separate methods for each menuItem, or create a single method that sets the textField to the string you call it with. Using the 2nd method, you would call the same function from all three menuItems, but pass a different string to it.
Also when creating UIs in maya, I highly recommend that you make the whole UI a class. It greatly simplifies the access of UI shared data and controls.
getControllerTextValues is querying the commands associated with the menu items, not the labels
What about :
from functools import partial # to combine values and arguments
def set_text_value(*args):
# the *args is because menu callbacks always add an extra bool on the end
cmds.textField('inputControllerName_TF', edit=True, text=args[0])
# in the menu:
menuItem('Foot', c = partial(set_text_value, "foot"))
menuItem('Hand', c = partial(set_text_value, "hand"))
Thanks for your assistance capper and Theodox, as for Classes Im not really familiar with them so im going to probably study that more and then attempt to use it. I also enjoyed your star wars and star trek references lol