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.