在使用Vray时,我正在编写一个脚本来简化繁琐的任务,但是我不得不使用intFields,它应该允许用户输入一个int值,该值在单击按钮时触发某个特定的操作。我只将代码简化为必要的部分。无论我将值更改为什么,脚本编辑器输出中的值总是为0。
import maya.cmds as cmds
idManagerUI = cmds.window(title='Vray ID Manager', s = False, wh = (300,500))
cmds.columnLayout(adj = True)
cmds.text (l = 'type in MultimatteID to select matching shaders \n or specify ObjectID to select matching objects \n __________________________________________ \n')
cmds.text (l = 'MultimatteID: \n')
cmds.intField( "MultimatteID", editable = True)
MultimatteIdButton = cmds.button(l = 'Go!', w = 30, h = 50, c = 'multimatteChecker()')
cmds.text (l = '\n')
cmds.showWindow(idManagerUI)
MultimatteIdInput = cmds.intField( "MultimatteID", q = True, v = True)
def multimatteChecker():
print MultimatteIdInput发布于 2017-03-25 18:37:50
有三件事:
首先,正如所写的那样,您不能确定intField MultimatteID实际上是否得到了您认为它应该具有的名称。Maya小部件名是唯一的,就像maya对象名称一样--您可以将它命名为MultimatteID,但实际上可以取回一个名为MultimatteID2的小部件,因为您有一个未删除的窗口(无论是否可见),其中有一个类似命名的控件。
其次,在创建窗口后,您粘贴的代码将立即查询控件的值。它应该总是打印出你在创作中给它的价值。
最后-不要在按钮中使用命令分配的字符串版本。当您从监听器中的代码移到工作脚本时,这是不可靠的。
这应该是你想做的事:
idManagerUI = cmds.window(title='Vray ID Manager', s = False, wh = (300,500))
cmds.columnLayout(adj = True)
cmds.text (l = 'type in MultimatteID to select matching shaders \n or specify ObjectID to select matching objects \n __________________________________________ \n')
cmds.text (l = 'MultimatteID: \n')
# store the intField name
intfield = cmds.intField( "MultimatteID", editable = True)
cmds.text (l = '\n')
# define the function before assigning it.
# at this point in the code it knows what 'intfield' is....
def multimatteChecker(_):
print cmds.intField( intfield, q = True, v = True)
#assign using the function object directly
MultimatteIdButton = cmds.button(l = 'Go!', w = 30, h = 50, c = multimatteChecker)https://stackoverflow.com/questions/43018531
复制相似问题