Package nukescripts :: Module captureViewer
[hide private]
[frames] | no frames]

Source Code for Module nukescripts.captureViewer

 1  """ 
 2  This module contains classes for performing a capture of the viewer. 
 3  """ 
 4   
 5  # TODO: Move renderdialog.ViewerCaptureDialog, renderdialog.ViewerCaptureDialogThread and renderdialog.showViewerCaptureDialog here as well, but without introducing a circular dependency with 
 6  # the renderdialog module. 
 7   
 8  import string, os 
 9  import nuke 
10   
11 -class CaptureViewer(object):
12 """ This class provides a way of capturing the contents of the viewer to disk. 13 """
14 - def __init__(self, flipbook, frameRange, viewer, selectedViews, defaultWritePath, customWritePath, doFlipbook, doCleanup):
15 self._flipbook = flipbook 16 self._frameRange = nuke.FrameRanges(frameRange.split(',')) 17 self._viewer = viewer 18 self._selectedViews = selectedViews 19 self._defaultWritePath = defaultWritePath 20 self._customWritePath = customWritePath 21 self._doFlipbook = doFlipbook 22 self._doCleanup = doCleanup
23
24 - def _performCleanup(self):
25 """ Remove temporary files created by a previous capture. 26 """ 27 outputContext = nuke.OutputContext() 28 fileKnob = self._viewer['file'] 29 30 frameList = self._frameRange.toFrameList() 31 for frame in frameList: 32 outputContext.setFrame( frame ) 33 fileName = fileKnob.getEvaluatedValue(outputContext) 34 35 if os.access(fileName, os.F_OK): 36 os.remove(fileName)
37
38 - def __call__(self):
39 """ Start the capture. 40 """ 41 writePath = self._customWritePath or self._defaultWritePath 42 self._viewer['file'].setValue(writePath) 43 44 # _performCleanup will remove whatever filepath is set in the self._viewer['file'] knob. 45 # So if this changes between runs then the old files wont get cleaned up, probably 46 # a bug. 47 if self._doCleanup: 48 self._performCleanup() 49 50 try: 51 nuke.executeMultiple((self._viewer,), self._frameRange, self._selectedViews, False) 52 except RuntimeError, msg: 53 if msg.args[0][0:9] == "Cancelled": 54 splitMsg = string.split(msg.args[0]) 55 msg = """ Render did not complete, do you want to show the completed range ? 56 Frame range %s contains %s frames but only %s finished. 57 """ % (self._frameRange, splitMsg[3], splitMsg[1]) 58 self._doFlipbook = nuke.ask(msg) 59 else: 60 nuke.message("Flipbook render failed:\n%s" % (msg.args[0],)) 61 self._doFlipbook = False 62 63 finally: 64 if not self._customWritePath: 65 self._viewer['file'].setValue(self._defaultWritePath) 66 67 if self._doFlipbook: 68 playbackPath = nuke.filename(self._viewer) 69 if playbackPath is None or playbackPath == "": 70 raise RuntimeError("Cannot run a flipbook on '%s', expected to find a filename and there was none." % (self._viewer.fullName(),)) 71 72 options = {} 73 options["lut"] = 'sRGB' 74 self._flipbook.run(playbackPath, self._frameRange, self._selectedViews, options)
75