Maya中的Python-查询复选框值 [英] Python in Maya - Query checkbox value

查看:126
本文介绍了Maya中的Python-查询复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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)

,然后在烘焙"函数中 id希望查询复选框以执行不同的操作,具体取决于选中的复选框...

    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) 

但是这给了我一个错误,说'value'是一个无效的标志...我不知道那是什么意思.

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

解决方案

您已经关闭了,查询标志只是告诉命令您要获取数据,而不是设置要查询的数据,它也必须出现在同样的命令,您只是缺少字段的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):,这与编写if 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,这是一个很棒的程序.

Im super new to python and i have this little spare time project going on. And i cant find a solution to the following problem:

I set up a GUI like this:

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)

and then later, inside the function 'Bake' id like to query the checkboxes to do different stuff, depending on what boxes are checked... like this:

    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...

when i try to run the script, i get a error saying that there is invalid syntax on the line if scaleValue = True:

i also tried using this:

mc.attributeQuery(translateBox,value=True) 

but that gives me an error, saying that 'value' is an invalid flag... i dont know what that means.

Some help here would be greatly appreciated!! Thanks guys!

解决方案

You were close, the query flag simply tells the command you want to get the data, rather than set, whatever you're queering, has to also appear in the same command, you're just missing the v=True flag for the fields.

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

Also, where you're chaining your if commands, seeing as your value can only be true or false, you can simply write if (scaleValue): which is the same as writing if 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')

Better yet, seeing as you're doing basically the same thing for these chains, we can simplify this:

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

The above is exactly the same as the code above this code.

Hope this helps, as @jonathon has also provided, the way you've written your UI can get very messy and hard to read, definitely read into QT Designer, it's a brilliant program.

这篇关于Maya中的Python-查询复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆