我在python中有这个代码,它必须查询为maya中的窗口创建的三个radiobuttons。这是我到目前为止的代码,我可以查询滑块但我不知道如何查询radiobuttons .. < / p>
import maya.cmds as cmds
#def function1(value):
def function1(value1,value2):
print(value1)
def function2(value):
print(value)
def createUI():
cmds.window("Window")
cmds.columnLayout( adjustableColumn=True )
value1 = cmds.intSliderGrp(label='number of moons', minValue=4, maxValue=20, value=12, field=True)
value2 = cmds.intSliderGrp(label='Distance from parent to child', minValue=5, maxValue=40, value=20, field=True)
DirectionControl = cmds.radioCollection()
Direction0 = cmds.radioButton( label='Front')
Direction1 = cmds.radioButton( label='Back')
Direction2 = cmds.radioButton( label='Random')
cmds.radioCollection( DirectionControl, edit=True, select=Direction0 )
cmds.button(label = "OK", command = lambda *args: function1(cmds.intSliderGrp(value1, query=True, value=True), cmds.intSliderGrp(value2, query=True, value=True),cmds.radioButtonGrp(Direction1, query=True, value=True)))
cmds.showWindow()
createUI()
#
这一行:
cmds.button(label = "OK", command = lambda *args: function1(cmds.intSliderGrp(value1, query=True, value=True), cmds.intSliderGrp(value2, query=True, value=True),cmds.radioButtonGrp(Direction1, query=True, value=True)))
如果我们删除与radiobuttons相关的语句,就有效。
答案 0 :(得分:4)
首先,在lambda函数中放入这么多东西没有任何意义。你需要考虑以更好的方式编写代码,以便维护它的人不会生你的气:P。更重要的是,下次当你回到你的代码时,它会更有意义。
其次,您需要考虑阅读maya命令文档,因为radionCollection和radioGroup不相同,并且radioCollection不会像您预期的那样返回任何值。
我的代码版本有点干净。
import maya.cmds as cmds
from functools import partial
#def function1(value):
def function1(value1,value2):
print(value1)
def function2(value):
print(value)
def createUI():
myWindow = "SomeWindow"
if maya.cmds.window(myWindow,ex=True):
maya.cmds.deleteUI(myWindow)
cmds.window(myWindow)
cmds.columnLayout( adjustableColumn=True )
value1 = cmds.intSliderGrp(label='number of moons', minValue=4, maxValue=20, value=12, field=True)
value2 = cmds.intSliderGrp(label='Distance from parent to child', minValue=5, maxValue=40, value=20, field=True)
DirectionControl = cmds.radioCollection()
Direction0 = cmds.radioButton( label='Front')
Direction1 = cmds.radioButton( label='Back')
Direction2 = cmds.radioButton( label='Random')
DirectionControl = cmds.radioCollection( DirectionControl, edit=True, select=Direction0 )
cmds.button(label = "OK", command = partial(passValue, value1, value2, DirectionControl))
cmds.setParent("..")
cmds.showWindow()
def passValue(value1, value2, DirectionControl, *args):
intValOne = cmds.intSliderGrp(value1, query=True, value=True)
intValTwo = cmds.intSliderGrp(value2, query=True, value=True)
radioCol = cmds.radioCollection(DirectionControl, query=True, sl=True)
getSelectRadioVal = cmds.radioButton(radioCol, query=True, label=True)
function1(intValOne, intValTwo)
function2(getSelectRadioVal)
createUI()
希望这个帮助