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.