1 """
2 This module contains classes for performing a capture of the viewer.
3 """
4
5
6
7
8 import string, os
9 import nuke
10
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
37
39 """ Start the capture.
40 """
41 writePath = self._customWritePath or self._defaultWritePath
42 self._viewer['file'].setValue(writePath)
43
44
45
46
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