Ron's suggestion is indeed the right way to do it.
but to still answer your initial question:
the python error message "name 'menubar' is not defined" says that the variable menubar was not defined before you actually try to use it. it works in your menu.py because somewhere above your three lines must be a line that actually defines that variable//, like e.g.
/menubar = nuke.menu("Nuke")
/that's why it can create the menu entry.
if you put that definition inside your function /importSharedToolbar()/ in myLib.py it should work, too.

but you're still better of implementing it the way Ron suggested. although basically the same procedure applies. to be able to create the menu entry in your custom menu.py (which you place into the centralised location) you still need to define that variable before you can add new menu entries.

on top of that, i'd avoid putting anything inside user directories. you'd have to do that with every new user that's created or a user might accidentally delete/change/overwrite stuff. and you don't really want to deal with that. especially the more users there are. so i suggest the following: - set the environment variable NUKE_PATH to point to your centralised directory (how to do it depends on the OS you're using). Nuke will automatically try to load init.py and menu.py from that location. - in that centralised location place the init.py and menu.py plus any gizmos, etc. that you want all users to be able to use and do all your other customization magic there. that way you'll only have to deal with one location where you need to modify files and not different home dirs on different machines. be careful, though, when editing them. you should do that in your own development environment so you don't break scripts, etc. that artists are actually using. and then copy the files from there into the central location.

cheers,
Holger


Jonathan King wrote:
So easy ... thanks Ron!

JCK

------------------------------------------------------------------------
*From: *"Ron Ganbar" <[email protected]>
*To: *"Nuke Python discussion" <[email protected]>
*Sent: *Monday, August 6, 2012 12:05:49 PM
*Subject: *Re: [Nuke-python] menu.py menubar shared for multiple users

You just need to place your menu.py in a centralized location that is accessible from all users (and all the gizmos, icons, scripts, etc, as well). Then in each individual home directory create an init.py file where you can use the following script to point to the centralized location:

import nuke

nuke.pluginAddPath('path/to/centralized/location/')


Enjoy,
Ron Ganbar
email: [email protected] <mailto:[email protected]>
tel: +44 (0)7968 007 309 [UK]
     +972 (0)54 255 9765 [Israel]
url: http://ronganbar.wordpress.com/



On 6 August 2012 18:52, Jonathan King <[email protected] <mailto:[email protected]>> wrote:

    Hi all,

    I might be thinking too simplistically, but I'm trying to create a
    menubar that is shared across multiple users so that we don't have
    to individually update our ~/.nuke/menu.py files each time a new
    gizmo is introduced.  When I import the following function and
call it, I run into a NameError that menubar does not exist. However when the three lines of code are run directly in menu.py,
    they work fine.  I can't seem to find any info on where menubar
    comes from, except that it is an instance of class Menu, a class
    that does not exist in python's memory even during a nuke
    session.  Any ideas on how to get this to work, or other ways to
    do the same thing?

    # a function in myLib.py
    def importSharedToolbar():
        # these three lines work if they are directly in menu.py
        import myNode
        MyToolbar = menubar.addMenu("MyToolbar")
        MyToolbar.addCommand("myNode", "myNode.myFunction()")


    # call made in menu.py
    import myLib
    myLib.importSharedToolbar()
    -- NameError: name 'menubar' is not defined

    JCK


    _______________________________________________
    Nuke-python mailing list
    [email protected]
    <mailto:[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
------------------------------------------------------------------------

_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

--
Holger Hummel  -  [email protected]

Celluloid Visual Effects, Paul-Lincke-Ufer 39/40, 10999 Berlin
phone +49 (0)30 / 54 735 220  -  [email protected]

_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to