in Programmer by
I have a series of Maya selection sets (e.g. body_all, upper_body, lower_body, eyes, brows, mouth, etc.) that contain all rig controls specific to that set, and I'm using command buttons in the picker to select the members of those sets.  For example, I have a "brows" command button that selects the members of the Maya selection set "brows", so with one click I can select all brow controls.  The benefit of using a command button over a normal selection button is that I can edit the selection set or generate the selection set on rig build, and the picker dynamically updates since it's just pointing to the set itself.  I can also use the same picker with different characters that have different controls for the brows, as long as they both have a "brows" selection set.

This all works very well, but by default command buttons do not change appearance after they are clicked in the same way a normal selection button does.  A selection button will stay highlighted white, which is nice because visually it tells the animator that the brows are selected.  A command button selects the brows and then returns to its normal un-highlighted color, so the animator has no visual confirmation that the brows are selected (aside from what he/she sees in the viewport).

Is there a way to change this behavior via script?  For example, on press, change color to white and stay white until a different button is pressed.  And also stay white if the animator shift-selects a second button.  Basically mimicking the behavior of a normal selection button, but with the more flexible functionality of the command button.  Hope that makes sense.  Thanks!

EDIT: I guess another idea would be to expand the functionality of the standard selection button so that it could select selection sets.

1 Answer

0 votes
by
 
Best answer

The command button is just not designed to do so.

But if you really want to do it, he is how you change command button within its command:

# change the color of the command button within its command:
thisBtn = cmds.MGPicker(q=True, currentItem=True)

# try to mimic semi-highlight or full-highlight color
semiHighlighted = (0.7,0.7,0.7, 1.0)
fullyHighlighted = (1.0, 1.0, 1.0, 1.0)
cmds.MGPickerItem(thisBtn, e=True, fillColor=semiHighlighted)

Another way around, you can write code in picker's mouse enter command, so whenever mouse enter the picker view, these command will be invoked:
# somehow grab these command buttons, usually you can do it by name instead of id.
# you need to name them in property editor.
# then you grab id by names:
commandBtn = cmds.MGPickerView(q=True, getIdFromName="brows_btn")[0]
# then check maya selection, and update button fill color, which coulc be normal color, semi-highlighted or fully-highlighted.

 

by

A better way to do it is to use the selection button, with a bit of manual work.

e.g. You create a select button, name it brows, or whatever. If your selection set in the Maya scene just differs in the namespace, then author the selectButton's members manually once and for all.

If the selection set might contain totally different nodes, then you can code in the picker's namespace changed command, use picker API to update the selectButton's member list on picker load time, based on the actual nodes in the selection set.

# grab the selection button by name or by hard-coded ids
# get the nodes from selection set
nodesToSet = " ".join(nodes)
cmds.MGPickerItem(selBtn, e=True, selectMembers=nodesToSet)



This is a better idea since the code execution only happens once, and for the rest of the time it will highlight itself depending on Maya selection, in C++.

Categories

...