函数无法从 Maya 中的字段中找到值 Python UI

Function cannot find the value from a field in Maya Python UI

我正在为我一直在处理的脚本构建 Maya UI,但是当我试图阻止多个 windows 时遇到问题。基本上,如果我不把它放在代码前面:

winID = 'vs-sfa'

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

一切正常,但随后使用可能会产生大量 windows,这将是有问题的。但是,当我添加此代码并尝试访问 textScrollList 字段中的值时,我得到 None。有什么建议么?这是代码..

winID = 'vs-sfa'
#Prevent multiple windows
if(cmds.window(winID, exists=True)):
    cmds.deleteUI(winID, window=True)

#Create new window 
window = cmds.window(winID, title="Create Sound from Animation", iconName='soundFromAnimW', widthHeight=(520, 400) )

#Tabs layout
tabs = cmds.tabLayout()
tab1 = cmds.columnLayout()

#Controls for the first tab
cmds.text(l='basic stuff')
cmds.setParent('..')
tab2 = cmds.columnLayout( adjustableColumn=True )

#Controls for the second tab
cmds.text( label='Some text with instructions and stuff' )
cmds.button( label='Update Selection', command='updateSel()' )
cmds.button( label='Close', command=('cmds.deleteUI(\"' + window + '\", window=True)') )
cmds.rowLayout(numberOfColumns=2, adjustableColumn=2, columnWidth2=[260,260] )
#The textScrollList fields, from which I get None
selection = cmds.textScrollList( numberOfRows=4, append=sel, allowMultiSelection=True, sc='updateAttrs()' )
freqs = cmds.textScrollList( numberOfRows=4, append=Cmaj )
cmds.setParent('..')
cmds.columnLayout(adjustableColumn=True)
attrs = cmds.textScrollList(numberOfRows = 9, append=attrsList, allowMultiSelection=True)
cmds.button(l='Assign Frequency', command='assignFreq()')
connections = cmds.textScrollList( numberOfRows=4, allowMultiSelection=True)
cmds.button(l='Remove assignment', command='removeFreq()')
cmds.button(l='Create sound', command='createSound()')
messages = cmds.textScrollList(numberOfRows=6, allowMultiSelection=True)
cmds.setParent('..')
cmds.tabLayout(tabs, e=True, tl=((tab1, 'Basic'),(tab2, 'Advanced')))
cmds.showWindow( window )

当我在 Maya 中 运行 您的代码时,出现以下错误:

# Error: name 'sel' is not defined
# Traceback (most recent call last):
#   File "<maya console>", line 26, in <module>
# NameError: name 'sel' is not defined # 

当您创建 textScrollList 时,您尝试在其中附加一个未定义且不存在的对象 sel

当您删除前两行以删除 window(如果存在)时它起作用的原因可能是因为您在脚本中进一步创建了 sel 变量,并且当您重新创建一个新的 window 变量现已定义,可以填充新创建的 textScrollList.

你可以做的是在你的 window 中调用它之前创建变量 sel 或者创建你的 textScrollList 空然后,当你定义 sel变量,编辑字段并在其中附加变量。