pythongui界面复选框数值选择并求和_Maya中的Python-查询复选框值

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值