Error interpreting this plugin (nuke / osx)

Hey everybody!

A few months ago I started to setup ayon for my studio, and I found the same issue as dan when I have to launch nuke (and hiero) from a Mac (mac studio, M4 chipset).

I also can not launch the DCC from the terminal, so I tried to debug and I found something interesting, here is what I did:

I first launch the “Terminal main” and then execute the command to launch Nuke (16.0v7).
Then from Nuke’s Script Editor I execute the menu.py script in order to have Ayon in the menu:

from ayon_core.pipeline import install_host
from ayon_nuke.api import NukeHost

host = NukeHost()
install_host(host)

I get this error:

Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "/Volumes/.../ayon/ayon-core/client/ayon_core/pipeline/context_tools.py", line 136, in install_host
    host.install()
  File "/Users/admin/Library/Application Support/AYON/addons/nuke_0.3.14/ayon_nuke/api/pipeline.py", line 129, in install
    add_scripts_menu()
  File "/Users/admin/Library/Application Support/AYON/addons/nuke_0.3.14/ayon_nuke/api/lib.py", line 2578, in add_scripts_menu
    studio_menu = launchfornuke.main(title=_menu.title())
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/.../ayon/ayon-core/client/ayon_core/vendor/python/scriptsmenu/launchfornuke.py", line 33, in main
    nuke_main_bar = _nuke_main_menubar()
                    ^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/.../ayon/ayon-core/client/ayon_core/vendor/python/scriptsmenu/launchfornuke.py", line 28, in _nuke_main_menubar
    assert len(menubar) == 1, "Error, could not find menu bar!"
           ^^^^^^^^^^^^^^^^^
AssertionError: Error, could not find menu bar!

It seems like it’s a specific Qt issue in MacOS only, with menubars.
I look at the function _nuke_main_menubar() in launchfornuke.py:

nuke_window = _nuke_main_window()
menubar = [i for i in nuke_window.children()
           if isinstance(i, QtWidgets.QMenuBar)]

assert len(menubar) == 1, "Error, could not find menu bar!"

nuke_window.children() can’t find any QMenuBar in Mac. I add before the assert this:

if not menubar:
    menubar = [nuke_window.menuBar()]

then I can finally open Nuke from the launcher! (I also add the fix in ayon-hiero)

I don’t know if this solution is the best but I hope this can help you !

Cheers