【问题标题】:Remove Menu Item in Maya using Python使用 Python 在 Maya 中删除菜单项
【发布时间】:2017-10-23 20:06:55
【问题描述】:

如何使用 Python 从主窗口中删除菜单项?我使用 MEL 让它工作,但我在 Python 中也需要它。

不工作的部分是find menu if exists and delete。我似乎在 Python 中找不到等价物。

Python(不工作)

import maya.cmds as cmds

if(???)
{
    #cmds.deleteUI('JokerMartini', menu=True )
}

cmds.menu(label='JokerMartini', tearOff=True, p='MayaWindow')
cmds.menuItem(label='Action 1', c= 'something.run()')
cmds.menuItem(divider=True)
cmds.menuItem(label='Action 2', c= 'something.run()')

梅尔(工作中)

if(`menu -exists JokerMartini`)
{
    deleteUI JokerMartini;
}
global string $gMainWindow;
setParent $gMainWindow;
menu -label "JokerMartini" -to true -aob true JokerMartini;    
menuItem -label "Action 1" -command "something";
menuItem -label "Rename..." -command "something";

【问题讨论】:

    标签: python maya mel


    【解决方案1】:

    这是一种创建主菜单项的方法:

    import maya.cmds as mc
    
    menuJM = "JM"
    labelMenu = "JokerMartini"
    
    mc.menu(menuJM, l=labelMenu, to=1, p='MayaWindow')
    mc.menuItem(l='Action 1', c='something.run()')
    mc.menuItem(d=True)
    mc.menuItem(l='Action 2', c='something.run()')
    

    对于删除,您应该使用这种方法:

    if mc.menu(menuJM, l=labelMenu, p='MayaWindow') != 0:
        mc.deleteUI(mc.menu(menuJM, l=labelMenu, e=1, dai=1))
        mc.deleteUI(menuJM)     
    
    mc.refresh()
    

    【讨论】:

    • 为什么有 2 次调用 mc.deleteUI? dai = 1 和 vis = 1 是什么意思?
    • @Jitesh、dai = deleteAllItems 和 vis 现在已弃用。尝试其中一个电话,然后两个电话,你就会明白为什么了。
    猜你喜欢
    • 2023-03-28
    • 2020-07-16
    • 1970-01-01
    • 2014-03-21
    • 2016-03-31
    • 1970-01-01
    • 2014-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多