Ad this code to your menu.py file:
# templates menu start
def createTemplatesMenu (origPath, menuObject):
tempDirs = os.listdir(origPath)
tempDirs.sort()
for tempDir in tempDirs:
tempDirPath = origPath + tempDir
if os.path.isdir(tempDirPath):
tmpMenu = menuObject.addMenu(tempDir)
createTemplatesMenu ((tempDirPath + "/"), tmpMenu)
if os.path.isfile(tempDirPath):
if (os.path.splitext(tempDirPath)[1] == ".nk"):
menuObject.addCommand(tempDir, "nuke.nodePaste(\"" + tempDirPath + "\")", "")
m = menubar.addMenu("&Templates")
createTemplatesMenu ("x:/nuke/templates/", m)
t = toolbar.addMenu("&Templates")
createTemplatesMenu ("x:/nuke/templates/", t)
# templates menu end
The script will scan through all subdirectories and .nk files in a given path and builds up a "Templates" menu by making submenus from subdirs and menuitems from .nk files. This way you just need to select a bunch of nodes and "Export Nodes As Script..." in nuke and save them. After restarting nuke, you can find your template comp in the Templates menu.