I'm trying to create a script in Python in Maya that will allow me to dynamically alter the image of a specific button and nothing else about that button. I'm crashing into some serious issues that I'll detail below:
import maya.cmds as cmds
import maya.mel as mel
cmds.refresh(cv=1, f=1)
gShelfTopLevel = mel.eval("global string $gShelfTopLevel; $temp = $gShelfTopLevel;")
currentShelf = cmds.tabLayout(gShelfTopLevel,q=1,st=1)
buttons = cmds.shelfLayout(currentShelf,q=1,ca=1)
buttonName = "Button 1"
for button in buttons:
if cmds.shelfButton(button, q=True, l=True) == buttonName:
cmds.shelfButton(button, h=35, w=35, e=1, i="icons/axis_Object.png", p=currentShelf )
#If this was working I'd have an if statement here for a second image.
break
Toggler()
class Toggler():
if ctx == 'moveSuperContext':
tool = 'Move'
mode = cmds.manipMoveContext(tool, q=1, m=1)
if mode != 2:
cmds.manipMoveContext(tool, e=1, m=2)
else:
cmds.manipMoveContext(tool, e=1, m=0)
if ctx == 'RotateSuperContext':
tool = 'Rotate'
mode = cmds.manipRotateContext(tool, q=1, m=1)
if mode != 0:
cmds.manipRotateContext(tool, e=1, m=0)
else:
cmds.manipRotateContext(tool, e=1, m=1)
if ctx == 'scaleSuperContext':
tool = 'Scale'
mode = cmds.manipScaleContext(tool, q=1, m=1)
if mode != 0:
cmds.manipScaleContext(tool, e=1, m=0)
else:
cmds.manipScaleContext(tool, e=1, m=2)
Firstly this is the script. What the button should do is defined at the bottom and as best as I can tell that is all fine. It was already existing code that I was handed.
My problems are as follows:
- The image changes for all buttons on the bar. This is incredibly unhelpful and I'm not sure why this would be the case.
- The names of all the buttons change to whatever buttonName is. So in this case, all buttons are renamed to "Button 1" which is also incredibly frustrating for me.
- The script on the original button is cloned to all other buttons.
An addendum to 2 is I've tried renaming my buttonName variable on the off chance that buttonName is an intrinsic variable assigned to these button scripts.
In the past I was able to accomplish editing just the image of a button with the following MEL code:
shelfButton -edit -image "icons/axis_World.png" $button;
I cannot figure out what is unique about this code compared to what I've done in Python but clearly there is something going on for me.
Any aid is welcome because at this point I'm completely at a loss. It looks like clicking any button on a shelf will cause it to iterate through all buttons on that shelf.
Thanks!