Let me start of by saying - you may be better of using the customization features of AYON using settings, to add custom tools.
ayon+settings://maya/scriptsmenu
The maya addon settings allow you to generate a custom menu directly from settings:
They won’t be listed under the AYON
menu - but under the separate unique menu (defaulting to “Custom Tools” but you can just change that around).
If you want to build complex menus there, you may use the Raw JSON builder and the tooltip will provide you a link that has more details on that JSON format. For sake of this discussion, here is a direct link to that page.
Bonus points here is that you do not need to adjust any AYON code - you can just customize the settings.
Does that help?
(Using the JSON format in our studio we have a deeply nested customized menu there with tons of custom scripts)
Generating the JSON from a folder containing scripts
Here’s a Gist that may guide you on automatically generating the Menu JSON if you happen to have nested folders of scripts and you want to use that folder structure to create the menu list:
If you really want to mess with the AYON menu itself and add menu entries in code there, then:
Code issues
cmds.menuItem(
"Bulk Rename Utility",
parent=internal_tools_menu,
command= bulk_renamer.show_ui()
)
This basically run the show UI command directly when generating the menu - not when pressing the button because the Python executes directly.
It should either be:
cmds.menuItem(
"Bulk Rename Utility",
parent=internal_tools_menu,
command= bulk_renamer.show_ui
)
Or:
cmds.menuItem(
"Bulk Rename Utility",
parent=internal_tools_menu,
command=lambda: bulk_renamer.show_ui()
)
I may recommend the latter to ensure the menu item doesn’t start passing arguments to your command that you may not be expecting.
Additionally, not sure what type of UI you’re making (whether it’s maya UI or Qt UI) but if it’s Qt UI be aware of garbage collecting:
def show_ui():
ui = BulkRenameUI()
ui.show()
In this case the variable ui
goes out of scope at the end of the function, so it may e.g. garbage collect your UI directly and instantly make it disappear. (unless you keep a reference to it or parent it to another UI object which then keeps the the reference to it)
This is then an easy ‘trick’ to work around it: (Although it may not be good practice).
def show_ui():
global ui
ui = BulkRenameUI()
ui.show()