Wow that is really annoying. Couldn't figure out why you're getting back
MenuItems instead of Menus (seems like a bug to me), but here's a (kind of
awkward) work around:
# previously:
menubar = nuke.menu("Nuke")
testMenu = menubar.addMenu("Test Menu")
testMenu.addCommand("Blur", "nuke.createNode(\"Blur\")")
testMenu.addCommand("Blur2", "nuke.createNode(\"Blur\")")
testMenu.addCommand("Blur3", "nuke.createNode(\"Blur\")")
# now:
def getMenu(menuBarName, menuName):
menubar = nuke.menu(menuBarName)
menu = menubar.findItem(menuName)
menuItems = list(menu.items())
menubar.removeItem(menuName)
newMenu = menubar.addMenu(menuName)
for item in menuItems:
newMenu.addCommand(str(item.name()), str(item.script()))
return newMenu
menu = getMenu("Nuke", "Test Menu")
JCK
----- Original Message -----
From: "Jake Richards" <[email protected]>
To: "Nuke Python discussion" <[email protected]>
Sent: Thursday, April 17, 2014 2:44:20 PM
Subject: [Nuke-python] menu and menuitem
Hello:
I was trying to use to find an existing menu and add some commands to it using
the .menu("") call but it appears this is returning a MenuItem object instead
of a Menu, and thus I can't call addCommand on it.
Nuke 8.0v3 in Linux:
menubar = nuke.menu("Nuke")
# Result:
testMenu = menubar.addMenu("Test Menu")
# Result:
testMenu
# Result:
<Menu object at 0x1d13b10>
menubar.menu("Test Menu")
# Result:
<MenuItem object at 0x1d139d8>
Shouldn't menubar.menu("Test Menu") return a Menu object?
.findItem seems to return a MenuItem as well:
menubar.findItem("Test Menu")
# Result:
<MenuItem object at 0x1d139a8>
Even iterating through .items() gives me a menuItem.
for i in menubar.items():
if i.name() == "Test Menu":
print i
# Result:
<MenuItem object at 0x1d137b0>
Am I totally not seeing the forest through the trees on how to get a Menu
object to then call addCommand?
Thank you!
Jake
--
--------------------------------------------
[email protected] 203-992-6319
LTD Blue Sky Studios
--------------------------------------------
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python