August 2020

Gizmo Snatch Tool (and how to install your Gizmos wisely)

tl;dr:  Snatch loads of Gizmos and Groups and install them like a PRO!

I don't know about you, but over the years I have curated a generous collection of Gizmos that I like having in my toolkit no matter where I go to do my comping thing. On the same note, whenever I am working on x or y company and I come across some new gems that I think would be a nice addition to my collection, I tend to snatch 'em, assuming of course that I am not infringing any copyright law and so on...

With that said, what this tool is going to allow you to do, is to essentially select as many Gizmos and Groups as you want to snatch, and save them all quickly in a folder of your choice, thus avoiding the "export as Gizmo" slow and tedious workflow, which apart from other more esoteric options, would seem like the obvious way to do it (correct me if I am wrong, please!)

2 - Distribute the code

As usual, copy the script and save it as a Python file called "b_gizmo_snatcher.py" where Nuke can find it. In other words, place it within the Nuke Path file structure. For more info, read my previous posts (or Google it, there´s tons of info covering this topic.)

code
Download File

3 - Edit the menu.py file

Now we have the Python module where Nuke can find it, we´re gonna add the following lines to our fantastic menu.py so that we can effectively use it:

n_menu = nuke.menu('Nuke')
b_menu = n_menu.addMenu('MenuName')
b_menu.addCommand('b_gizmo_snatcher', 'b_gizmo_snatcher.main_function()', 'any hotkey of your choice')


Save the menu.py and restart Nuke.

Alternatively, you could load the script in the Script Editor and run the "main_function()" at the end, but that's a little too nerdy, don't do that.

4 - Try it!

You'll notice that there is a brand new Nuke menu in your upper menu bar, listing the new 'b_gizmo_snatcher' command and its chosen hotkey. Now just select as many Gizmos and Groups as you want to snatch and run the tool.

A tiny Nuke Panel like this one should appear:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Select your "snatch" folder and click ok.

And voila, navigate to the chosen folder and you should find there all the Gizmos and Groups you've previously selected. By the way, as a side note, when snatching actual Gizmos and not Grizmos or Groups, the tool is first going to convert the Gizmo into a Group and then export the Group to the folder, adding the suffix "_toGroup" to the original Gizmo's name... just so you know!

bonus snippet!!

Now, after having snatched, created, and downloaded your favorite Gizmos, it's time to deploy them within your little Nuke path. While you can just drop them inside the .nuke folder and use the command "update" inside the "Other/All plugins" menu on Nuke's Toolbar, this is probably the laziest and less organized way to go.

Alternatively, as you probably already know, you can create menus and submenus on Nuke's Toolbar to add your Gizmos, using these simple commands:

nuke.menu("Nodes").addMenu("MyMenu", icon = "MyMenuLogo.png")
toolbar.addCommand("MyMenu/MySubMenu/ToolName", "nuke.createNode("ToolName")")

Although there's nothing wrong with this option, just think of having to write one line of code for each of the Gizmos you wanted to add to your menus, in addition to having to create and name those menus by hand. Yuck!

Now, one smart way to do this, would be to have all these gizmos distributed in folders and subfolders named as we want our Nuke menus and submenus to be named, and somehow write some hacky snippet that will automatically create the menus based off of these folders, name them accordingly, and list all the contained tools, as well as adding the menu icon again, automatically. For this to work (in this implementation I am sharing), we have to ensure 4 things:

1 - that the folders will be named according to this syntax: <gizmos_JohnDoe>. Namely, the word "gizmo" an underscore "_" and any name we wanted, in this case, "JohnDoe".

2 - that the icon to be used will be named exactly like the name after the underscore, in this case, "JohnDoe" and it will be a PNG image. I.e: "JohnDoe.png"

3 - that the folder will be on the same root where the menu.py is.

4 - that there will not be more than two nested levels in the gizmo folders, meaning there can be only subfolders inside the gizmo folders (to create subcategories), but not sub-subfolders.

With that out of the way, just copy this little snippet inside your menu.py, save it and you should be good to go!

code
################# Import a lot of tools 

# Import Gizmos

toolbar = nuke.menu("Nodes");
gizmodir = os.path.dirname(__file__)
print "GIZMODIR: ", gizmodir

def deploy_gizmos():

    for gd in os.listdir(gizmodir):
        
        upper_path = os.path.join(gizmodir,gd)
            
        if gd.startswith('gizmos_') and os.path.isdir(os.path.join(gizmodir,gd)):
            nuke.pluginAddPath('./'+gd)
            
            for sub_gd in os.listdir(os.path.join(gizmodir,gd)):
                if sub_gd.startswith('gizmos_') and os.path.isdir(os.path.join(gizmodir,gd,sub_gd)):
                    lower_path = os.path.join(gizmodir,gd,sub_gd)
                    nuke.pluginAddPath('./' + sub_gd)

    for gd in sorted(os.listdir(gizmodir), key=lambda f: f.lower()):

        if gd.startswith('gizmos_') and os.path.isdir(os.path.join(gizmodir,gd)):
            print gd[7:], gd[7:]+'.png'
            menu = toolbar.addMenu(gd[7:], gd[7:]+'.png')
            nuke.pluginAddPath('./'+gd)
            
            for gizmo in sorted(os.listdir(os.path.join(gizmodir,gd)), key=lambda f: f.lower()):
                if gizmo.endswith('.gizmo'):
                    menu.addCommand(gizmo[:-6], 'nuke.createNode("'+gizmo[:-6]+'")')
                    
            for sub_gd in os.listdir(os.path.join(gizmodir,gd)): 
                if sub_gd.startswith('gizmos_') and os.path.isdir(os.path.join(gizmodir,gd,sub_gd)):
                                                
                    super_menu = gd[7:]
                    sub_menu = sub_gd[7:]        
                    combined_menu = super_menu + "/" + sub_menu
                    to_plugin_path = "'./"+sub_gd +"'"
                    to_plugin_path = os.path.join(gizmodir,gd,sub_gd)
                        
                    menu = toolbar.addMenu(combined_menu, sub_gd[7:]+'.png')
                    nuke.pluginAddPath(to_plugin_path)    
                    
                    for gizmo in sorted(os.listdir(os.path.join(gizmodir,gd,sub_gd)), key=lambda f: f.lower()):
                        if gizmo.endswith('.gizmo'):
                            menu.addCommand(gizmo[:-6], 'nuke.createNode("'+gizmo[:-6]+'")')
                            
deploy_gizmos()
                

 

Read more →