Maya Python UI出现在属性编辑器中



这是我第一次来到这里,我一直在努力与python编码处理,弄清楚如何更新每个动作或鼠标事件的东西。

最近,每当我尝试测试我的脚本时,我经常在属性编辑器中看到一些按钮和布局面板,当它应该在我创建的窗口中。我怎样才能停下来呢?

我不认为我可以在这里张贴代码,因为它大约1000代码长,但我怎么能找到一种方法来防止类似的事情?是因为我使用了太多的setParent('..')函数吗?

如果你的按钮等出现在错误的布局,这可能是因为你调用UI命令后,一些其他功能已经重置现有的父。

如果你想确保你的控件在正确的位置,你需要存储你创建的任何窗口/布局/面板的名称,并在你开始制作小部件之前显式地将它们设置为父类。否则,育儿基本上就是"最后被创造的东西"。您可以这样验证:

# make a button out of context
import maya.cmds as cmds
xxx = cmds.button('boo')
# ask the parent of what we just made....
print cmds.control(xxx, q=True, p=True)
## Result: u'MayaWindow|MainAttributeEditorLayout|formLayout2|AEmenuBarLayout|AErootLayout|AEselectAndCloseButtonLayout' # 
如果你创建一个顶层容器(窗口或面板),

Parentage将被切换:

w = cmds.window()
c = cmds.columnLayout() 
b = cmds.button("bar")
# ask b's parent....
print cmds.control(b, q=True, p=True)
## Result: window3|columnLayout49  #

你也可以显式地切换父节点:

def make_a_layout(window_name):
    w = cmds.window(window_name)
    c = cmds.columnLayout()
    return c
layout_a = make_a_layout('window_a')
# any future widgets go into this layout...
print cmds.button("layout 1 a") 
#     window_a|columnLayout55|layout_1_a
layout_b = make_a_layout('window_b')
# now this is the active layout
print cmds.button("layout 2 a ")  
#     window_b|columnLayout56|layout_2_a
# explicitly set the parent to the first layout
# now new widgets will be there
cmds.setParent(layout_a)
print cmds.button("layout 1 b")
#  window_a|columnLayout56|layout_1_b

可以看到,每次创建新布局时都会设置当前父级。你可以用setParent ('..')弹出一个关卡,或者用setParent('your_layout_here')显式地将其设置为任何布局。

相关内容

最新更新