Maya 中的 Python - 查询复选框值

标签 python user-interface checkbox maya

我对 python 非常陌生,我正在做这个小小的业余项目。 我找不到以下问题的解决方案:

我设置了一个像这样的 GUI:

flWin = mc.window(title="Foot Locker", wh=(210,85))
mc.columnLayout()
mc.text(label='Frame Range')
rangeField = mc.intFieldGrp(numberOfFields=2,value1=0, value2=0)
mc.rowColumnLayout(numberOfRows=2)
translateBox = mc.checkBox(label='Translation',value=True)
mc.button(label="Bake it!", w=60, command="Bake()")
rotateBox = mc.checkBox(label='Rotation',value=True)
mc.button(label='Key it!', w=60, command='Key()')
scaleBox = mc.checkBox(label='Scale')
mc.showWindow(flWin)

然后在函数“Bake”内 我喜欢查询复选框来执行不同的操作,具体取决于选中的框...如下所示:

    translateValue = mc.checkBox(translateBox, query=True)
    rotateValue = mc.checkBox(rotateBox, query=True)
    scaleValue = mc.checkBox(scaleBox, query=True)

    if scaleValue = True:          
        if rotateValue = True:     
            if translateValue = True:
                mc.parentConstraint ('LockCator', Selection, n='LockCatorConstraint')
                mc.scaleConstraint('LockCator', Selection, n='selectionScale')

            else:
               mc.parentConstraint ('LockCator', Selection, n='LockCatorConstraint', skipTranslate=True) 
               mc.scaleConstraint('LockCator', Selection, n='selectionScale')


bla bla bla... you get the trick...

当我尝试运行脚本时,收到一条错误消息,指出行上存在无效语法 if scaleValue = True:

我也尝试过使用这个:

mc.attributeQuery(translateBox,value=True) 

但这给了我一个错误,说“值”是一个无效标志......我不知道这意味着什么。

这里的一些帮助将不胜感激! 谢谢大家!

最佳答案

你很接近,查询标志只是告诉命令你想要获取数据,而不是设置,无论你在查询什么,也必须出现在同一个命令中,你只是缺少v =True 字段标志。

translateValue = mc.checkBox(translateBox, query=True, value=True)
rotateValue = mc.checkBox(rotateBox, query=True, value=True)
scaleValue = mc.checkBox(scaleBox, query=True, value=True)

此外,在链接 if 命令的地方,由于值只能为 true 或 false,因此您可以简单地编写 if (scaleValue): ,这与编写 相同如果scaleValue == True:

if (scaleValue):
    if (rotateValue):     
        if (translateValue):
            mc.parentConstraint ('LockCator', Selection, n='LockCatorConstraint')
            mc.scaleConstraint('LockCator', Selection, n='selectionScale')
        else:
            mc.parentConstraint ('LockCator', Selection, n='LockCatorConstraint', skipTranslate=True) 
            mc.scaleConstraint('LockCator', Selection, n='selectionScale')

更好的是,由于您对这些链执行的操作基本相同,因此我们可以简化此操作:

skipTrans = True if scaleValue and rotateValue and translateValue else False
mc.parentConstraint ('LockCator', Selection, n='LockCatorConstraint', skipTranslate=skipTrans) 
mc.scaleConstraint('LockCator', Selection, n='selectionScale')

上面的代码和上面这段代码是完全一样的。

希望这会有所帮助,正如 @jonathon 也提供的那样,您编写 UI 的方式可能会变得非常困惑且难以阅读,绝对可以读入 QT Designer,这是一个出色的程序。

关于Maya 中的 Python - 查询复选框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19099287/

相关文章:

java - 安卓 : Creating GUI programmatically at run time in java

jquery - 通知我按钮的 UI 交互

android - 使用 StringBuilder 追加

python - 通过重复数组索引对数组值求和

Python:IndexError:列表索引超出范围错误

python - 在 if 语句中比较三个变量

asp.net - 如何在复选框的 CheckedChanged 事件中获取中继器项目?

python - Django 模板语言 : Using a for loop with else

c# - 适用于 Windows 应用程序的 Monobjc 和 Mac UI

python - 将文件上传到 FastAPI 时如何使用 HTML 复选框发送可选参数?