Creating a new menu for Custom Gizmos

Written by Synicade Herrera on .

I had TONS of trouble trying to figure out how to make a menu, so here is my tutorial. (Keep in mind, this is a tutorial for super ultra mega beginners) Be SURE you read the directories carefully during this tutorial!

What we will do: We will add a new menu to your "Nodes" menu. This will make your custom gizmos easier to access.

First, we need to create some directories and files.

Navigate to Nuke x.x/plugins/ (My directory is: /usr/local/Nuke6.1v3-32/plugins/) (sometimes Nuke x.x is known as .nuke) *

In your "plugins" folder, create a folder called "user", this is where you will keep your menu.py, init.py files for organizing your custom menu.

Enter your new "user" folder, and create a folder called "gizmos", this is where you will keep your gizmos. Then, create a folder called "icons", you can keep your super special awesome cusom menu icons here.

Now that we have our directories, copy your custom gizmos into the "gizmos" folder, and your Custom Menu Icon into your "icons" folder. Don't have one? Here is one that I made: http://i51.tinypic.com/2w6v613_th.png (Remember to rename the image!) Keep in mind: Your menu may not be visable if you do not have an icon.

Now, everything is just about set up. We just need to Create/Edit our init.py and menu.py files, creating a .txt (or any other sort of text file) then naming itmenu.py or init.py will do fine.

What we should have so far:

Our lovely Plugins folder

 

Open your menu.py file, and type this:

1
2
3
4
5
6
7
8
9
10
import sys
import nuke
 
 
print 'Loading Lab Tools...'
menubar = nuke.menu("Nuke")
 
# Custom Lab Tools
toolbar = nuke.toolbar("Nodes")
m = toolbar.addMenu("MENU NAME", icon="MENU ICON.png")

Lovely, we have created our menu! But our menu does not contain any Gizmos.

To insert a Gizmo into the Menu, type:

1
m.addCommand("Example 1", "nuke.createNode(\"Example 2\")", icon="ICON.png")
Example 1: This is the name that wil appear in your menu, this name does not need to match your Gizmo, name it whatever you want. (This will not show up in your DAG, See Example 2)
Example 2: This is the Gizmo you want Nuke to create. If you put it in your "gizmos" folder, you'll be fine. Be sure to replace "Example 2" with the exact name of your Gizmo. You can change the name of your gizmo and then change "Example 2" to match if you don't like the name of the Gizmo. (This will be the name that shows up in your DAG)
If you want more than one Menu within your Menu.py file,  this is what your menu.py file should look like:
Be sure you set an icon for each of them, you can use the same Icon for all of them also.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sys
import nuke
 
 
print 'Loading Lab Tools...'
menubar = nuke.menu("Nuke")
 
# Custom Lab Tools
toolbar = nuke.toolbar("Nodes")
m = toolbar.addMenu("CUSTOM MENU 1", icon="ICON NAME HERE.png")
 
m.addCommand("CUSTOMGIZMO", "nuke.createNode(\"CUSTOMGIZMO\")", icon="IMAGE NAME HERE.png")
m.addCommand("CUSTOMGIZMO", "nuke.createNode(\"CUSTOMGIZMO\")", icon="IMAGE NAME HERE.png")
m.addCommand("CUSTOMGIZMO", "nuke.createNode(\"CUSTOMGIZMO\")", icon="IMAGE NAME HERE.png")
 
# Custom Lab Tools
toolbar = nuke.toolbar("Nodes")
m = toolbar.addMenu("CUSTOM MENU 2", icon="ICON NAME HERE.png")
 
m.addCommand("CUSTOMGIZMO", "nuke.createNode(\"CUSTOMGIZMO\")", icon="IMAGE NAME HERE.png")
m.addCommand("CUSTOMGIZMO", "nuke.createNode(\"CUSTOMGIZMO\")", icon="IMAGE NAME HERE.png")
m.addCommand("CUSTOMGIZMO", "nuke.createNode(\"CUSTOMGIZMO\")", icon="IMAGE NAME HERE.png")
 
# Custom Lab Tools
toolbar = nuke.toolbar("Nodes")
m = toolbar.addMenu("CUSTOM MENU 3", icon="ICON NAME HERE.png")
 
m.addCommand("CUSTOMGIZMO", "nuke.createNode(\"CUSTOMGIZMO\")", icon="IMAGE NAME HERE.png")
m.addCommand("CUSTOMGIZMO", "nuke.createNode(\"CUSTOMGIZMO\")", icon="IMAGE NAME HERE.png")
m.addCommand("CUSTOMGIZMO", "nuke.createNode(\"CUSTOMGIZMO\")", icon="IMAGE NAME HERE.png")

 

Each menu starts with these lines of code:
"#Custom Lab Tools
toolbar = nuke.toolbar("Nodes")
m=toolbar.addMenu("CUSTOM MENU", icon="ICON NAME.png")"
Create or Remove as many of these as you wish.

 

 Nuke is addicted to init.py files, and will not survive without them.

Create an init.py file in the same directory as your menu.py file, and type this:
1
2
3
4
5
6
7
# Copyright (c) 2009 The Foundry Visionmongers Ltd.  All Rights Reserved.
 
## init.py
## loaded by nuke before menu.py
 
nuke.pluginAddPath('./gizmos')
nuke.pluginAddPath('./icons')
Great, you have made your first menu! (hopefully)
Mess around with it for a bit. I've created a menu for each Gizmo type. Example: If I have a Filter Gizmo, I will put it in my "Custom Filters" menu. Same with Transform Gizmos, so on and so on.
IF NUKE DOES NOT LOAD:
Check menu.py for basic erorrs
Be sure you removed all unneeded "m.addCommand(CUSTOMGIZMO", "nuke.createNode(\CUSOMGIZMO\")", icon="IMAGE NAME HERe.png")
If you have an extra, nuke will look for it, but not find it, and therefore crash.
Check all directories and links, if Nuke does not find what you sent it looking for, it will not open.
Remove "nuke.pluginAddPath('./icons')" from your init.py if you chose not to creat an icons folder, the same applies if you did not make a gizmos folder (Not using an icon for your menu system may make your menu invisible).
You can reverse any changes by simply removing your "user" folder (I would reccomend saving your gizmos though).
* Keep in mind, directories change depending on your operating system. If you cannot find it, run this installer until it asks you where you want to install it. Go to that folder (DO NOT RE-COMPLETE INSTALLATION)
** Nuke may not start properly if you do not have an icon for your new menu, or your menu may be unaccessable.

Comments   

 
+1 # Justin MacDonald 2012-09-27 12:38
Hi,

Forgive me if I am asking elementary questions but I am just learning Python for the first time.

Just wanted to ask what exactly the first few lines do?

" import sys
import nuke

print 'Loading Lab Tools...'
menubar = nuke.menu("Nuke ")

# Custom Lab Tools "

What do these lines actually do?

Cheers.
J
 
 
0 # ronaldo reyes 2017-07-11 16:21
thank you for your tutorial, it worked for me!! Awesome!! :), for super ultra newbie like me. :)
 

You have no rights to post comments

We have 2865 guests and 91 members online