首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >intField不显示更改

intField不显示更改
EN

Stack Overflow用户
提问于 2017-03-25 15:56:42
回答 1查看 135关注 0票数 0

在使用Vray时,我正在编写一个脚本来简化繁琐的任务,但是我不得不使用intFields,它应该允许用户输入一个int值,该值在单击按钮时触发某个特定的操作。我只将代码简化为必要的部分。无论我将值更改为什么,脚本编辑器输出中的值总是为0。

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-25 18:37:50

有三件事:

首先,正如所写的那样,您不能确定intField MultimatteID实际上是否得到了您认为它应该具有的名称。Maya小部件名是唯一的,就像maya对象名称一样--您可以将它命名为MultimatteID,但实际上可以取回一个名为MultimatteID2的小部件,因为您有一个未删除的窗口(无论是否可见),其中有一个类似命名的控件。

其次,在创建窗口后,您粘贴的代码将立即查询控件的值。它应该总是打印出你在创作中给它的价值。

最后-不要在按钮中使用命令分配的字符串版本。当您从监听器中的代码移到工作脚本时,这是不可靠的。

这应该是你想做的事:

代码语言:javascript
运行
复制
    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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43018531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档