通常,当我使用单选按钮选项运行脚本时,您选择一个单选按钮选项,然后使用按钮激活它。我曾经将菜单gui放在函数之外:但自从我学会导入maya脚本后,我开始将菜单界面包装在gui函数中,这意味着我的单选按钮技术现在不再有效。我也不知道如何让它工作。脚本本身非常简单:导入脚本后只需选择一个单选按钮选项,然后使用按钮创建一个形状:至少它应该是这样工作的。相反,我没有错误,也没有创建任何形状,我不知道什么东西坏了
'''
import cubeTestTemp
reload (cubeTestTemp)
cubeTestTemp.gui()
'''
import maya.cmds as cmds
#Creates ui.
if cmds.window("cubeWin", exists =True):
cmds.deleteUI("cubeWin", window = True)
myWindow = cmds.window("cubeWin",t='DS shapeDemo V1',w=200, h=500, toolbox=True)
column = cmds.columnLayout(adj=True)
#Creates variable to indicate the check box status. 1=Checked 0=Not Checked.
cubeNum1 = 0
cubeNum2 = 0
#Creates Button funtion.
def defaultButtonPush(*args):
#The Print checks if button is pushed and what is the check box status.
print "Button is pushed."
print cubeNum1
#Check box argument finds the status of the variable and determines what to do.
#Eather create a cube or display a error dialog box.
if cubeNum1 == 1:
print "Cube Creation sucessful"
cmds.polyCube()
print "Button is pushed."
print cubeNum2
if cubeNum2 == 1:
print "Sphere Creation sucessful"
cmds.polySphere()
def gui(*args):
#Creates check box.
#In the onCommand Script (onc) and offCommand Script (ofc) flags all commands must be made in between double quotes.
cmds.radioCollection()
cmds.radioButton(label='Cube',align='left',onCommand="cubeNum1 = 1", offCommand="cubeNum1 = 0")
cmds.radioButton(label='Sphere',align='left',onCommand="cubeNum2 = 1", offCommand="cubeNum2 = 0")
#Creates Button.
cmds.button( label='Execute', command=defaultButtonPush ,align='left' )
cmds.showWindow()
这是修改后的脚本。问题在于脚本的范围。“onCommand”在其自己的范围内执行,该范围具有自己的“cubeNum”变量
另一种方法是仅在需要时读取单选按钮状态
相关问题 更多 >
编程相关推荐