def run(self):
        frame_ranges = nuke.FrameRanges(self._frameRange.value().split(','))
        views = self._selectedViews()
        rootProxyMode = nuke.root().proxy()
        try:
            nuke.Undo().disable()
            nuke.root().setProxy(self._useProxy.value())

            if (self.isBackgrounded()):
                print frame_ranges
                make_out(self._nodeSelection)
                nuke.executeBackgroundNuke(
                    nuke.EXE_PATH,
                    self._nodeSelection,
                    frame_ranges,
                    views,
                    self._getBackgroundLimits(),
                    continueOnError=self._continueOnError.value())
            else:
                if (self.skipExisting()):
                    nuke.addBeforeFrameRender(skippy, nodeClass='Write')
                else:
                    nuke.removeBeforeFrameRender(skippy, nodeClass='Write')
                make_out(self._nodeSelection)
                nuke.executeMultiple(
                    self._nodeSelection,
                    frame_ranges,
                    views,
                    continueOnError=self._continueOnError.value())
        except RuntimeError, e:
            if self._exceptOnError or e.args[0][
                    0:
                    9] != "Cancelled":  # TO DO: change this to an exception type
                raise
Example #2
0
 def run(self):
     frame_ranges = nuke.FrameRanges(
         self._frameRange.value().split(','))
     views = self._selectedViews()
     try:
         nuke.Undo().disable()
         if (self.isBackgrounded()):
             nuke.executeBackgroundNuke(
                 nuke.EXE_PATH,
                 self._nodeSelection,
                 frame_ranges,
                 views,
                 self._getBackgroundLimits(),
                 continueOnError=self._continueOnError.value())
         elif self._termRender.value():
             terminal_render(self._nodeSelection, frame_ranges, views,
                             self._numInstances.value(),
                             self._numThreads.value(),
                             self._maxMem.value())
         else:
             nuke.executeMultiple(
                 self._nodeSelection,
                 frame_ranges,
                 views,
                 continueOnError=self._continueOnError.value())
     except RuntimeError, e:
         if self._exceptOnError or e.args[0][
                 0:
                 9] != "Cancelled":  # TO DO: change this to an exception type
             raise
Example #3
0
    def run(self):
        if self.isTimelineWrite() and self._frameServerRender.value():
            from hiero.ui.nuke_bridge.nukestudio import scriptSaveAndReRender
            scriptSaveAndReRender()
            return

        frame_ranges = nuke.FrameRanges(self._frameRange.value().split(','))
        views = self._selectedViews()
        rootProxyMode = nuke.root().proxy()
        try:
            nuke.Undo().disable()
            nuke.root().setProxy(self._useProxy.value())
            if (self.isBackgrounded()):
                nuke.executeBackgroundNuke(
                    nuke.EXE_PATH,
                    self._nodeSelection,
                    frame_ranges,
                    views,
                    self._getBackgroundLimits(),
                    continueOnError=self._continueOnError.value())
            else:
                nuke.executeMultiple(
                    self._nodeSelection,
                    frame_ranges,
                    views,
                    continueOnError=self._continueOnError.value())
        except RuntimeError, e:
            if self._exceptOnError or e.args[0][
                    0:
                    9] != "Cancelled":  # TO DO: change this to an exception type
                raise
Example #4
0
def customBackgroundRender():
    class ShapePanel(nukescripts.PythonPanel):
        def __init__(self, node):
            nukescripts.PythonPanel.__init__(self, 'CustomUI')
            self.rpNode = node
            self.paragraph = nuke.String_Knob('paragraph', 'Paragraph',
                                              '%s' % 5)
            self.memory = nuke.String_Knob('memory', 'Memory', '%s' % 4096)
            self.thread = nuke.String_Knob('thread', 'Thread', '2')
            for k in (self.paragraph, self.memory, self.thread):
                self.addKnob(k)

    p = ShapePanel('CustomUI')
    if p.showModalDialog():

        x = int(p.paragraph.value())
        y = p.memory.value()
        z = int(p.thread.value())
        a = int(nuke.root()["first_frame"].value() - 1)
        b = int(nuke.root()["last_frame"].value() + 1)
        c = (b - a) // x
        d = range(a, b, c)

        for e in range(0, x):
            write = nuke.selectedNode()
            wviews = write['views'].value().split(' ')

            if e == x - 1:
                nuke.executeBackgroundNuke(nuke.EXE_PATH, [write],
                                           nuke.FrameRanges('%s-%s' %
                                                            (d[e] + 1, b - 1)),
                                           wviews, {
                                               'maxThreads': z,
                                               'maxCache': '%sM' % y
                                           },
                                           continueOnError=True)

            else:
                nuke.executeBackgroundNuke(nuke.EXE_PATH, [write],
                                           nuke.FrameRanges(
                                               '%s-%s' % (d[e] + 1, d[e + 1])),
                                           wviews, {
                                               'maxThreads': z,
                                               'maxCache': '%sM' % y
                                           },
                                           continueOnError=True)
    else:
        pass
Example #5
0
 def render(frameList):
     _maxCache = str(max(nuke.memory("max_usage") / 1097152, 16) * 4) + "M"
     try:
         t = nuke.executeBackgroundNuke(
             nuke.EXE_PATH,
             [renderNode],
             nuke.FrameRanges(frameList),
             nuke.views(),
             {"maxThreads": 1, "maxCache": _maxCache},
         )
         THREAD_FRAMES[t] = frameList
     except Exception as e:
         print e
	def render_next(self):
		if not self.nodes:
			return
		
		node = self.nodes[0]
		del self.nodes[0]  # it's taken, so remove it
		
		f = int(node['first'].value())
		l = int(node['last'].value())
		ranges = nuke.FrameRanges()
		ranges.add(nuke.FrameRange('%d-%d' % (f,l)))
		
		pid = nuke.executeBackgroundNuke(self.path, [node], ranges, ['main'], {})
		self.pids[pid] = node.name()
		self.pids_done[pid] = False
		self.pids_time[pid] = time.time()
		
		print 'Started rendering: %s, pid: %d' % (node.name(), pid)
    def _createIntermediateNode(self):
        """Create a write node to render out the current node so that output may be used for flipbooking."""
        flipbooktmp = self._getIntermediatePath()

        fieldname = "file"
        if self._useProxy.value():
            fieldname = "proxy"

        fixup = nuke.createNode("Group",
                                "tile_color 0xff000000",
                                inpanel=False)
        with fixup:
            fixup.setName("Flipbook")
            inputNode = nuke.createNode("Input", inpanel=False)
            shuffle = nuke.createNode("Shuffle", inpanel=False)
            shuffle.knob("in").setValue(self._channels.value())
            write = nuke.createNode("Write",
                                    fieldname + " {" + flipbooktmp + "}",
                                    inpanel=False)
            write.knob('file_type').setValue(self._getIntermediateFileType())
            write.knob('views').fromScript(" ".join(self._selectedViews()))

            if self._getIntermediateFileType() == "exr":
                write.knob('compression').setValue("B44")
            if self._burnInLUT.value():
                lut = self._getLUT()
                if lut != "None":
                    write.knob('colorspace').setValue(lut)
            outputNode = nuke.createNode("Output", inpanel=False)
        #If called on a Viewer connect fixup node to the one immediately above if exists.
        if self._node.Class() == "Viewer":
            fixup.setInput(
                0,
                self._node.input(
                    int(nuke.knob(self._node.fullName() + ".input_number"))))
        else:
            fixup.setInput(0, self._node)

        try:
            # Throws exception on render failure
            if (self.isBackgrounded()):
                nuke.executeBackgroundNuke(
                    nuke.EXE_PATH, [write],
                    nuke.FrameRanges(self._frameRange.value().split(',')),
                    self._selectedViews(), self._getBackgroundLimits(),
                    self._continueOnError.value(), self._flipbookEnum.value(),
                    self._getOptions(write))
            else:
                nuke.executeMultiple(
                    (write, ),
                    nuke.FrameRanges(self._frameRange.value().split(',')),
                    self._selectedViews(), self._continueOnError.value())
        except RuntimeError, msg:
            if msg.args[0][0:9] == "Cancelled":
                splitMsg = string.split(msg.args[0])

                msg = """Render did not complete, do you want to show the completed range?
Frame range %s contains %s frames but only %s finished.""" % (
                    self._frameRange.value(), splitMsg[3], splitMsg[1])
                if nuke.ask(msg) == False:
                    nuke.delete(fixup)
                    fixup = None
            else:
                nuke.delete(fixup)
                fixup = None
                nuke.message("Flipbook render failed:\n%s" % (msg.args[0], ))
Example #8
0
def create_snapshot_fullres(snapImageFile=None,
                            writeUniqueName=None,
                            fakeFrameRange=None):
    """
    Check if input process and viewer input are valid, bake LUT, write full-res image, thumbnail, chmod 0444 both
    :param snapImageFile: Absolute path to .jpeg
    :param writeUniqueName: name of temporarily Write node
    :param fakeFrameRange: current frame X represented as "X-X"
    """
    try:
        initial_node = nuke.selectedNodes()[0]
        if initial_node.Class() == "Viewer":
            initial_node.setSelected(False)
            initial_node = initial_node.dependencies()[-1]
            initial_node.setSelected(True)
    except IndexError:
        nuke.message("Select node from which to render full-res snapshot")
        raise BaseException
    ip_node = nuke.activeViewer().node().knob('input_process_node').value()
    viewerInput = nuke.toNode(ip_node)
    viewerProcess = nuke.ViewerProcess.node()
    is_ip_valid = False
    is_vp_valid = False
    if 'None' not in str(viewerProcess):
        is_vp_valid = True
        root = nuke.root()
        root.begin()
        newVp = nuke.createNode(
            viewerProcess.Class(),
            viewerProcess.writeKnobs(nuke.WRITE_NON_DEFAULT_ONLY
                                     | nuke.TO_SCRIPT),
            inpanel=False)
        root.end()
        tmpViewerProcess = nuke.toNode(newVp.name())
        tmpViewerProcess.setInput(0, nuke.selectedNode())
        initial_node.setSelected(False)
        tmpViewerProcess.setSelected(True)
        initial_node = nuke.selectedNodes()[0]
    else:
        print "\n! No valid IP attached to the Viewer, going on..."
    if 'Node' in str(type(viewerInput)) or 'Gizmo' in str(type(viewerInput)):
        is_ip_valid = True
        newIp = copy_viewer_input(viewerInput)
        tmpViewerInput = nuke.toNode(newIp.name())
        tmpViewerInput.setInput(0, nuke.selectedNode())
        initial_node.setSelected(False)
        tmpViewerInput.setSelected(True)
    else:
        print "\n! No valid VI attached to the Viewer, going on..."

    nuke.nodes.Colorspace(name="cspTmp89", colorspace_in="sRGB").setInput(
        0, nuke.selectedNode())
    csp = nuke.toNode('cspTmp89')  # This name is cool enough to be hard-coded
    csp.setSelected(True)
    if is_ip_valid:
        tmpViewerInput.setSelected(False)
    if is_vp_valid:
        tmpViewerProcess.setSelected(False)

    finWriteTxt = "finWrite = " + '"' + \
                  r"import os\nfrom PIL import Image\nimgPath = nuke.thisNode()['file'].getValue()\nim = Image.open(imgPath)\nimSize = ('', 100)\nim.thumbnail(imSize, Image.ANTIALIAS)\nimgPathThumb = str(imgPath).replace('jpg', 'thumb') + '.jpg'\nim.save(imgPathThumb, 'JPEG')\nos.chmod(imgPath, 0444)\nos.chmod(imgPathThumb, 0444)" + \
                  '"' + r"; exec finWrite"
    print "\n~ Writing screenshot: " + snapImageFile
    nuke.nodes.Write(name=writeUniqueName,
                     file=snapImageFile,
                     colorspace="sRGB",
                     file_type="jpeg").setInput(0, nuke.selectedNode())
    writeUniqueNode = nuke.toNode(writeUniqueName)
    writeUniqueNode.knob('afterRender').setValue(finWriteTxt)
    nuke.executeBackgroundNuke(nuke.EXE_PATH, [writeUniqueNode],
                               nuke.FrameRanges(fakeFrameRange), ["main"], {})
    nuke.delete(writeUniqueNode)
    nuke.delete(csp)
    if is_ip_valid:
        nuke.delete(tmpViewerInput)
    if is_vp_valid:
        nuke.delete(tmpViewerProcess)
Example #9
0
    def _createIntermediateNode(self):
        """Create a write node to render out the current node so that output may be used for flipbooking."""
        flipbooktmp = self._getIntermediatePath()

        fieldname = "file"
        if self._useProxy.value():
            fieldname = "proxy"

        fixup = nuke.createNode("Group",
                                "tile_color 0xff000000",
                                inpanel=False)
        with fixup:
            fixup.setName("Flipbook")
            inputNode = nuke.createNode("Input", inpanel=False)
            shuffle = nuke.createNode("Shuffle", inpanel=False)
            shuffle.knob("in").setValue(self._channels.value())
            if self._useRoi.value():
                crop = nuke.createNode("Crop", inpanel=False)
                crop['box'].fromScript(self._roi.toScript())
            write = nuke.createNode("Write",
                                    fieldname + " {" + flipbooktmp + "}",
                                    inpanel=False)
            write.knob('file_type').setValue(self._getIntermediateFileType())
            selectedViews = self._selectedViews()
            write.knob('views').fromScript(" ".join(selectedViews))

            if self._getIntermediateFileType() == "exr":
                write.knob('compression').setValue("B44")
                # Set the 'heroview' to be the first of the selected views. If we don't
                # do this then then 'heroview' is by default set to be 1 which may not
                # be a valid view for this clip. The 'heroview' is used as a fallback if
                # no view has been set on the reader. This assumes the user has selected
                # sensible views if they haven't then the write may still fail.
                if len(selectedViews) > 0:
                    firstView = nuke.OutputContext().viewFromName(
                        selectedViews[0])
                    write.knob('heroview').setValue(firstView)

            writeColorspace = ""

            if self._burnInLUT.value():
                # The user has chosen to burn the viewer transform into the intermedate render so set the colorspace
                # on the Write node appropriately.
                writeColorspace = self._getBurninWriteColorspace()
            else:
                # The viewer transform is not being burnt into the intermediate render, set the Write node's colorspace
                # to whatever the current working space is - when reading the file back in the flipbook we'll ssume
                # the media was written out in the working space.
                rootNode = nuke.root()
                if rootNode:
                    workingSpaceKnob = rootNode.knob("workingSpaceLUT")
                    if workingSpaceKnob:
                        writeColorspace = workingSpaceKnob.value()

            if writeColorspace:
                write.knob('colorspace').setValue(writeColorspace)

            outputNode = nuke.createNode("Output", inpanel=False)
        #If called on a Viewer connect fixup node to the one immediately above if exists.
        if self._node.Class() == "Viewer":
            fixup.setInput(
                0,
                self._node.input(
                    int(nuke.knob(self._node.fullName() + ".input_number"))))
        else:
            fixup.setInput(0, self._node)

        try:
            # Throws exception on render failure
            if (self.isBackgrounded()):
                nuke.executeBackgroundNuke(
                    nuke.EXE_PATH, [write],
                    nuke.FrameRanges(self._frameRange.value().split(',')),
                    self._selectedViews(), self._getBackgroundLimits(),
                    self._continueOnError.value(), self._flipbookEnum.value(),
                    self._getOptions(write))
            else:
                nuke.executeMultiple(
                    (write, ),
                    nuke.FrameRanges(self._frameRange.value().split(',')),
                    self._selectedViews(), self._continueOnError.value())
        except RuntimeError, msg:
            if msg.args[0][0:9] == "Cancelled":
                splitMsg = string.split(msg.args[0])

                msg = """Render did not complete, do you want to show the completed range?
Frame range %s contains %s frames but only %s finished.""" % (
                    self._frameRange.value(), splitMsg[3], splitMsg[1])
                if nuke.ask(msg) == False:
                    nuke.delete(fixup)
                    fixup = None
            else:
                nuke.delete(fixup)
                fixup = None
                nuke.message("Flipbook render failed:\n%s" % (msg.args[0], ))