from maya import cmds
def link_at_target_values(target_values):
sel = cmds.MGPickerView(q=True, sel=True) or []
error_msg = "Please select picker items to link to the attribute button at the target values."
if len(sel) < 2:
print(error_msg)
return
target_attr_btn = sel[-1]
if cmds.MGPickerItem(target_attr_btn, q=True, type=True) != "attributeButton":
print("The target_attr_btn is not actually a attribute button")
return
for btn in sel[:-1]:
cmds.MGPickerLink(s=btn, t=target_attr_btn, targetValues=target_values)
# select all the buttons, and select the attribute button as the last one, and specify target values:
link_at_target_values("0,1")
Since v2.4, if you want to use API, the code can be simplified as shown above, because the `cmds.MGPickerView(q=True, sel=True)` now returns the selected buttons in selection order.
Since v2.4, you can also create attrLink for the int/double attribute button for multiple target values. Use the link tool to drag buttons onto an int/double attribute button, an input field will pop up to enable the user to input values, separated by ",". The same rule applies to the relationship panel.