in Programmer by

Hi Miguel,

I have a right click menu on a select button that is suppose to toggle an attribute of the member of this button


Head ctrl -> right click menu to hide and unhide the head offset ctrl


import maya.cmds as mc

#get current namespace
currentNamespace = mc.MGPickerView(namespace=True, q=True)

#get the ID of the active button 
activeButton = mc.MGPicker(q=True, currentItem=True)

#get a list of all Members of the button
buttonMembers = mc.MGPickerItem(activeButton, q=True, selectMembers=True)

#get offset vis State
currentState = mc.getAttr(currentNamespace+':'+buttonMembers[0]+'.headOffset')
#switch pivot vis
if currentState == 0:
   mc.setAttr(currentNamespace+':'+buttonMembers[0]+'.headOffset', 1)
    mc.setAttr(currentNamespace+':'+buttonMembers[0]+'.headOffset', 0)

The problem with this code is get ID of the active button

If the button is selected, it works fine. If another button (like the wrist) is selected in the picker and I'm using the right lick menu on the head button I get the ID of the wrist and not of the head button.

So my question. How do I get the ID of the button that the right click menu is connected to, the menu parent button id.

I tried:

buttonID = mc.MGPickerMenu(q=True, p=True)

but I gent an error:

# Error: Maya command error
# Traceback (most recent call last):
#   File "<maya console>", line 2, in <module>
#   File "<string>", line 2, in MGPickerMenu
# RuntimeError: Maya command error #


Thanks for your GREAT GREAT picker I love it :)



1 Answer

0 votes
Best answer
This is an issue that only happened in v2. You are supposed to get the correct ID by calling

activeButton = mc.MGPicker(q=True, currentItem=True)

But in v2 there is a bug that this does not always return the active button ID. I have fixed that in my code base, please wait until the next release.

Sorry for the inconvenience.