RuntimeError /第22行:未找到对象'Test'

问题描述 投票:0回答:1

我正在开始python脚本编写,而我遇到了问题:

import maya.cmds as cmds

win = 'win'
if cmds.window(win, exists = True):
    cmds.deleteUI(win)

win = cmds.window(win, t = 'My First Almost-Functional Script')
cmds.showWindow(win)
cmds.columnLayout(adj = True)

cmds.separator(h = 25)

nameCtrl = cmds.textFieldGrp(l = 'Name :', editable = True) 
cmds.separator(h = 25 )
cmds.intSliderGrp( min=0, max=50, step=1, f =True )
cmds.separator(h = 25 )
cmds.button ('Test', l = 'Go! ', c = 'Check()')

Test = 'Test'

def Check():
    value = cmds.intSliderGrp('Test', q=True, v=True)
    if value==0 :
        cmds.error( "A null value has been chosen, nothing will happen." )
    else :
        cmds.headsUpMessage('Something is supposed to Happen')

我不明白为什么它会向我返回错误,指出在第22行中找不到对象'Test'...有人可以帮助我吗?

python runtime-error maya
1个回答
0
投票

您有此错误,因为maya找不到名称为'Test'的滑块。

尝试一下:

import maya.cmds as cmds

win = 'win'
if cmds.window(win, exists = True):
    cmds.deleteUI(win)

win = cmds.window(win, t = 'My First Almost-Functional Script')
cmds.showWindow(win)
cmds.columnLayout(adj = True)

cmds.separator(h = 25)

nameCtrl = cmds.textFieldGrp(l = 'Name :', editable = True) 
cmds.separator(h = 25 )
slider = cmds.intSliderGrp( min=0, max=50, step=1, f =True )
cmds.separator(h = 25 )
cmds.button ('Test', l = 'Go! ', c = 'Check()')

def Check():
    value = cmds.intSliderGrp(slider, q=True, v=True)
    if value==0 :
        cmds.error( "A null value has been chosen, nothing will happen." )
    else :
        cmds.headsUpMessage('Something is supposed to Happen')

实际上,您在窗口中创建了一些布局。并且您的滑块处于布局中。因此,您需要在UI中获取滑块的完整路径,并将其提供给查询值的元素。

希望对您有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.