in Programmer by
I have a command button that is toggling the visibility of my rig spline controls using the Maya toggle command.

Can I use this button to toggle the visibility of my controls in the picker too?

1 Answer

0 votes
edited by

Yes. It is exposed in picker API.

If the control buttons you want to toggle is just a single one or just a few:

newValue = not cmds.MGPickerItem(controlId, q=True, visible=True)
cmds.MGPickerItem(controlId, e=True, visible=newValue)

If there are many of them, it is a better idea to "group" these controls  by naming them with a single string:

# Select these control buttons to toggle, input a name in the attribute editor. e.g.: toggleControls
from maya import cmds
buttonsToToggle = cmds.MGPickerView(q=True, getIdFromName="toggleControls")
if buttonsToToggle:
    newValue = not cmds.MGPickerItem(buttonsToToggle[0], q=True, visible=True)
    for btn in buttonsToToggle:
        cmds.MGPickerItem(btn, e=True, visible=newValue)

In the coming MG-Picker Studio v2, we support actual group. With v2 you can just group them, and toggle the visibility of group itself using MGPickerItem command.

edited by

Here is more information on the naming thing.

In the picker file, Each button has an id, like selectButton5, commandButton23, etc.

The id is guaranteed to be unique for a certain button, and it stays unchanged as long as the button still there so when you use MGPickerItem command API, you need to feed in an id string.

However, hard-coding id for API calls is not flexible, it won't work if you delete the button and recreate one, and it can only stand for one button. That is where the name property comes into play.

You can select multiple buttons in the view, and name them with the same string:

so that later you can use MGPickerView -getIdFromName "name" to get the list of button ids with the name. 

In API point of view, a name is like an id for a virtual group and it avoids the hard-coded button ids in MGPickerItem calls.


For more API reference:

Check out the "For Programmer" section.