我正在尝试在Maya中用Python创建一个脚本,该脚本允许我动态更改特定按钮的图像,而无需更改该按钮的任何其他内容。我遇到了一些严重的问题,我将在下面详述:
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)
首先,这是剧本。按钮应该做什么是在底部定义的,我能说的最好的是一切都很好。我得到的是已经存在的代码
我的问题如下:
2的一个附录是我尝试重命名buttonName变量,因为buttonName很可能是分配给这些按钮脚本的内在变量
在过去,我能够使用以下MEL代码仅编辑按钮的图像:
shelfButton -edit -image "icons/axis_World.png" $button;
与我在Python中所做的工作相比,我不知道这段代码有什么独特之处,但很明显,这对我来说是有意义的
任何援助都是受欢迎的,因为现在我完全不知所措。看起来,单击工具架上的任何按钮都会使其遍历该工具架上的所有按钮
谢谢
我无法与您的
Toggler()
类交谈,因为我对它的用途感到非常困惑,但下面的脚本片段在Maya 2018.4中完全可用:我没有使用您使用的
width
、height
和parent
标志。除此之外,所有内容都或多或少与您自己的代码相同。也许编辑parent
没有按预期工作?您的mel
等效命令也没有设置此标志相关问题 更多 >
编程相关推荐