Thread: Menu from List, question about how lists work

Reply to Thread
Results 1 to 3 of 3
  1. #1 Menu from List, question about how lists work 
    Join Date
    Jul 2008
    Posts
    105
    Hey guys, I created this pretty cool py file that builds some menus in Nuke for my company. One of the menus, called ICE, is a directory listing of all of the shows we work on, with sub menus for episodes, then within each episode it shows every Nuke file, and lets you open them.

    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:

    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+'"'+')')
    -----
    VFX Creative Director // Encore Hollywood
    iMDB
    Reply With Quote  

  2. #2  
    Join Date
    Feb 2007
    Posts
    993
    Smart move avoiding os.walk. It does not play nice with network storage or large directory trees.

    Anyway, the simplest way, using a modified version of what you've already got, would probably be to collect and build a list of .nk files first (or dict of sub-paths & .nk filenames if you need it) for a project, then test it for content and only build that submenu if the list contains anything.

    Also, if you've still got Andy Lewis working there, give him a high-five for me and tell him Nathan says hey.
    Reply With Quote  

  3. #3  
    Join Date
    Mar 2009
    Location
    Cilver City CA
    Posts
    687
    if theres a standard comp dir and subdirs for packages like _comp/nuke/... or comp/ae/... you could run up to that dir and check. If not, then it will be a little harder. The lazier the file management of the artists the harder it is building pipeline specific tools
    Reply With Quote  

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. addCommand to File menu
    By alex.oddbratt in forum NUKE from The Foundry
    Replies: 6
    Last Post: June 10th, 2011, 03:06 AM
  2. Building a computer for doing 3d work
    By chiefraven in forum Hardware & Tech Talk
    Replies: 4
    Last Post: April 30th, 2010, 12:31 AM
  3. A question for recruiters
    By compguru in forum Professional Career Advice!
    Replies: 5
    Last Post: April 2nd, 2010, 01:35 PM
  4. Check list when shooting for match moving.
    By RobPhoboS in forum VFX Supervision / Pre-Production
    Replies: 1
    Last Post: March 17th, 2010, 01:55 PM
  5. Python, adding icon to new toolbar sub menu?
    By mattdleonard in forum NUKE from The Foundry
    Replies: 2
    Last Post: March 6th, 2010, 04:42 PM
Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts