It works great, however, currently, it shows EVERY show in the main directory that we work on, which is a lot. We only use Nuke on a small portion of the shows we work on, so I was hoping to limit the scope of the menu build to show only those shows/episodes that have Nuke files in them in the menu.
Not sure how to do it, my logic is a little backwards.
Also, I did play with os.walk to sniff out the entire contents of our server, but it was hammering it pretty hard and taking about 10 minutes to process, so I am limiting things by using listdir instead.
Here’s my code:
import os, nuke
def isNuke(file):
check = file.split(".")[-1]
if check == "nk":
return True
else:
return False
def mylistdir(directory):
filelist = sorted(os.listdir(directory))
return [x for x in filelist if not (x.startswith('.'))]
def fileType(file):
return file.split(".")[-1]
#DIRECTORY LISTING
def directory():
root = '/data/ice/PROJECTS/'
if os.path.isdir(root) == False:
root = '/Volumes/share/data/diablo2/PROJECTS/'
mainMenu = nuke.menu('Nuke')
encore= mainMenu.addMenu('ICE')
encore.addCommand("Refresh","directory("+'"'+root+'"'+")","#^r")
encore.addSeparator()
topDirs = mylistdir(root)
for dirs in topDirs:
topDirsPathed = os.path.join(root,dirs)
#print dirs
topMenu = encore.addMenu(dirs)
subDirs = mylistdir(topDirsPathed)
for dirs in subDirs:
subDirsPathed = os.path.join(topDirsPathed,dirs)
#print " "+dirs
subMenu = topMenu.addMenu(dirs)
nukeContent = subDirsPathed + "/03_projectfiles/nuk"
nukeSubFolders = []
if os.path.isdir(nukeContent) == True:
nukeDirs = nukeContent
nukeSubFolders = mylistdir(nukeDirs)
for dirs in nukeSubFolders:
nukeSubFoldersPathed = os.path.join(nukeDirs,dirs)
if os.path.isdir(nukeSubFoldersPathed):
nukeFiles = mylistdir(nukeSubFoldersPathed)
for files in nukeFiles:
if isNuke(files):
#print " "+files
filesPathed = os.path.join(nukeSubFoldersPathed,files)
fileList = subMenu.addCommand(str(files), 'nuke.scriptOpen('+'"'+filesPathed+'"'+')')
Post a Comment