Feb 27, 2012

Nuke createwritedir script with multiple views

Hi, just jumped into a stereo project, and found that couple things not working properly with nuke. For example the good, ol' createwritedir script, that creates directory before rendering, doesn't handle the '%V' view tag in filenames, so I post here an updated version. This however creates directory for every view, because didn't find a way create them separately, as the script is not called in render for every view, only once.
Here is the code snippet. Sorry for misaligned lines. Anyone knows a better way for displaying code?
 def createWriteDir():  
     import nuke, os  
     import re  
     #view = nuke.thisView()  
     views = nuke.views()  
     file = nuke.filename(nuke.thisNode())  
     dir = os.path.dirname(file)  
     viewdirs = []  
     
     if re.search('%V', dir):    # replacing %V with view name  
         for v in views:  
             viewdirs.append(re.sub('%V', v, dir))  

     if len(viewdirs) == 0:  
         osdir = nuke.callbacks.filenameFilter(dir)  
         if not os.path.isdir(osdir):  
             os.makedirs (osdir)  
     else:  
         for vd in viewdirs:  
             osdir = nuke.callbacks.filenameFilter(vd)  
             if not os.path.isdir(osdir):  
                 os.makedirs (osdir)  
                 print 'Directory (with viewname) created: %s' % (osdir)  
(I edited the script, there was an unnecessary try: except part)

No comments:

Post a Comment