我有一个既有textScrollList又有optionMenu的窗口。我想在文本列表中选择更改时刷新选项菜单项。更新optionMenu项每次在textScrollList中更改选择内容
不确定从这一开始。
我使用普通的玛雅Python。
我有一个既有textScrollList又有optionMenu的窗口。我想在文本列表中选择更改时刷新选项菜单项。更新optionMenu项每次在textScrollList中更改选择内容
不确定从这一开始。
我使用普通的玛雅Python。
基本技巧就是确保您的更新函数的定义方式可以让它知道optionMenu和textScrollList的名称,以便编辑它们。简单的方法是在两个项目声明并存储在变量中后定义回调函数 - 只要这个函数全部在一个范围内,python就会通过闭包自动插入所需的值 - 它比手动操作更加优雅
这里有一个很小的例子
w = cmds.window()
c = cmds.columnLayout()
sl = cmds.textScrollList(append = ['a', 'b', 'c'])
op = cmds.optionMenu(label = 'test')
cmds.menuItem('created by default')
# the callback is defined after the ui so it knows the values of 'sl' and 'op'
def edit_options():
# gets a list of selected items from the textScroll
selected = cmds.textScrollList(sl,q=True, si=True)
# loop through existing menus in the optionMenu and destroy them
for item in cmds.optionMenu(op, q=True, ill=True) or []:
cmds.deleteUI(item)
# add a new entry for every item in the selection
for item in selected:
cmds.menuItem(label = item, parent = op)
# and something not dependent on the selection too
cmds.menuItem(label = 'something else', parent = op)
# hook the function up - it will remember the control names for you
cmds.textScrollList(sl, e=True, sc = edit_options)
cmds.showWindow(w)
更多的背景:http://techartsurvival.blogspot.com/2014/04/maya-callbacks-cheat-sheet.html
您必须使用一个函数来填充文本滚动并将其附加到selectCommand标志上。
您可能需要使用局部通道的文字广告栏名称ARG在功能
希望它能帮助。
您能否提供一些代码吗? – DrHaze