in Programmer by

I would like to be able to update the visuals of the picker attribute buttons when they are changed outside of the picker.
This command works fine for this.

mc.MGPickerItem(button, e=True, view=view, attributeValue=value)

The issue is that this MGPicerItem call also runs the preChange and postChange commands associated with the button id.

How can I update the picker button visuals without running the command of the button?

1 Answer

0 votes
by
 
Best answer

Indeed the attribute button's change command will be executed when the attribute value gets actually changed.

So if you don't wanna execute that, you need to pre-record the change command, clear it, and set the value, set back the change command.

Mabe using a python context would be a good idea. Something like:

from maya import cmds
btnId = 'attributeButton1'
viewId = cmds.MGPicker(q=True, activePickerView=True)

class AttributeButtonDisableChangeCmdCtx(object):
    def __init__(self, buttonId, viewId):
        self._btn = buttonId
        self._view= viewId
        self._preChangeCmd = ""
        self._postChangeCmd = ""

    def __enter__(self):
        self._preChangeCmd = cmds.MGPickerItem(self._btn, q=True, preChangeCommand=True, view=self._view)
        self._postChangeCmd = cmds.MGPickerItem(self._btn, q=True, postChangeCommand=True, view=self._view)
        cmds.MGPickerItem(self._btn, e=True, preChangeCommand="", view=self._view)
        cmds.MGPickerItem(self._btn, e=True, postChangeCommand="", view=self._view)

    def __exit__(self, *_, **__):
        cmds.MGPickerItem(self._btn, e=True, preChangeCommand=self._preChangeCmd, view=self._view)
        cmds.MGPickerItem(self._btn, e=True, postChangeCommand=self._postChangeCmd, view=self._view)

When you use it:

with AttributeButtonDisableChangeCmdCtx(btnId, viewId):
    cmds.MGPickerItem(btnId, e=True, atv=True, view=viewId)


Using context make it safer that the change command will be restored.

Categories

...