4
$\begingroup$

Compositor Node Setup

Using the compositor node setup above, when I hit F12, it makes a new pass and the rendered images are automatically saved. The problem is that the new render erases the previous one that was saved in my folder.

How can I prevent this?

I've already unchecked the "overwrite" option in the output panel in the properties editor, I did not see any similar options in the compositor editor.

I just want Blender to create a "render01" if a render is already there, exactly like in the outliner!

$\endgroup$
4
  • 2
    $\begingroup$ I is not clear to me what you expect. The file output is designed to do what is doing: when you render it will save the layers/passes that are connected to it to the designated output path. Are you expecting to generate a new file and rename it every single time? Or do you want to disable the node temporarily until you decide to save the result? If so you can do this by muting the node, so that it stops working until you enable it back. The overwrite function works only for the output of the "composite" node. To save to a new renamed file,most likely you are going to need a script. $\endgroup$
    – user1853
    Commented Mar 20, 2019 at 15:07
  • 3
    $\begingroup$ by the way, disabling the "overwrite" box on the output panel doesn't do renaming either. It is meant to skip saving the files that are already rendered in an animation. $\endgroup$
    – user1853
    Commented Mar 20, 2019 at 15:13
  • 1
    $\begingroup$ If you are saving passes individually consider using a more robust file format like EXR multilayer. EXR will keep your values linear and you can avoid misinterpretations in color spaces later. See: blender.stackexchange.com/questions/16152/…' and blender.stackexchange.com/questions/53300/combining-exr-files/… using EXR multilayer would make it quite easy to change the base name once before hitting the render button. $\endgroup$
    – user1853
    Commented Mar 21, 2019 at 17:04
  • $\begingroup$ One of the links has a scripted way to set the layers. Maybe that same script can be edited so that it can check if the output file exists and change the name for a new output. I don't speak python, but I'm sure someone here can help with that. $\endgroup$
    – user1853
    Commented Mar 21, 2019 at 17:09

3 Answers 3

7
+50
$\begingroup$

Thinking ahead, you want the Output Path in sync with all the File Output Nodes of the compositor.

I think one easy way to solve this is adding a 'version number' to all output paths (as usual) and keep all file names in sync. Here is a quick'n dirty Add-on to address that. Once you add v and some arbitrary number to the Output Path, a new 'slider' appears in the Output Area, which allows to change the actual version string on the fly.

enter image description here

render_version.py

# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

bl_info = {
    "name": "Render Version",
    "description": "Output version number control",
    "author": "p2or",
    "version": (0, 0, 2),
    "blender": (2, 80, 0),
    "location": "Properties > Output > Render Version",
    "warning": "", # used for warning icon and text in addons panel
    "wiki_url": "",
    "tracker_url": "",
    "category": "Render"
}

import bpy
import os
import re
from sys import platform
import webbrowser


# ------------------------------------------------------------------------
#    Scene Properties
# ------------------------------------------------------------------------

def rv_update(self, context):
    context.area.tag_redraw()
    scene = context.scene
    render = scene.render

    # Replace the render path
    render.filepath = version_number(
            render.filepath, 
            scene.rv.rdr_ver
        )
    
    # Replace file output
    if not scene.render.use_compositing or \
        not scene.rv.sync_comp or \
        not scene.node_tree:
        return
    
    nodes = scene.node_tree.nodes
    output_nodes = [n for n in nodes if n.type=='OUTPUT_FILE']
    
    for out_node in output_nodes:
        if "LAYER" in out_node.format.file_format:
            out_node.base_path = version_number(
                out_node.base_path, 
                scene.rv.rdr_ver)
        else:
            for out_file in out_node.file_slots:
                out_file.path = version_number(
                    out_file.path, 
                    scene.rv.rdr_ver)
    return None


class RVSettings(bpy.types.PropertyGroup):

    rdr_ver : bpy.props.IntProperty(
        name = "Render Version",
        description="Render Version",
        default = 1, 
        min = 1,
        update = rv_update)
        
    sync_comp : bpy.props.BoolProperty(
        name = "Sync Compositor",
        description="Sync version string with File Output nodes",
        default = True)

# ------------------------------------------------------------------------
#    Operators
# ------------------------------------------------------------------------

class RVOpenOutputDirectory(bpy.types.Operator):
    """Open up Output Directory in File Browser"""
    bl_idname = "rv.output_directory"
    bl_label = "Open Output Directory in File Browser"
    bl_description = "Output Directory"
    bl_options = {'INTERNAL'}
        
    def execute(self, context):
        fp = os.path.dirname(context.scene.render.frame_path())
        try:
            if platform.startswith('darwin'):
                webbrowser.open("file://{}".format(fp))
            else:
                webbrowser.open(fp)
        except OSError:
            self.report({'INFO'}, "No Folder")
        return {'FINISHED'}


class RVOutNodesCleanup(bpy.types.Operator):
    """Remove version strings from File Output Nodes"""
    bl_idname = "rv.remove_version_strings"
    bl_label = "Remove Version Strings from File Output Nodes"
    bl_options = {'REGISTER', 'UNDO'}

    @classmethod
    def poll(cls, context):
        space = context.space_data
        return space.type == 'NODE_EDITOR'

    def remove_version(self, fpath):
        match = re.search(r'(v\d+)', fpath)
        delimiters = ("-", "_", ".")
        if match:
            head, tail = fpath.split(match.group(0))
            if tail.startswith(delimiters):
                tail = tail[1:]
            fpath = head + tail
            return fpath[:-1] if fpath.endswith(delimiters) else fpath
        else:
            return fpath
    
    def execute(self, context):
        scene = context.scene    
        nodes = scene.node_tree.nodes
        output_nodes = [n for n in nodes if n.type=='OUTPUT_FILE']
        
        if not output_nodes:
            self.report({'INFO'}, "Nothing to operate on")
            return {'CANCELLED'}
            
        for out_node in output_nodes:
            if "LAYER" in out_node.format.file_format:
                out_node.base_path = self.remove_version(out_node.base_path)
                for layer in out_node.layer_slots:
                    layer.name = self.remove_version(layer.name)
            else:
                out_node.base_path = self.remove_version(out_node.base_path)
                for out_file in out_node.file_slots:
                    out_file.path = self.remove_version(out_file.path)
            
            scene.rv.sync_comp=False
        return {'FINISHED'}


# ------------------------------------------------------------------------
#    Drawing
# ------------------------------------------------------------------------

def draw_rv(self, context):
    """Append Properties and Operators to the Output Area"""
    rv = context.scene.rv
    if re.search("v\d+", context.scene.render.filepath) is not None:
        layout = self.layout
        #col = layout.column()
        row = layout.row(align=True)
        row.prop(rv, "rdr_ver") #NODE_COMPOSITING
        row.prop(rv, "sync_comp", text="", toggle=True, icon="IMAGE_RGB_ALPHA") 
        row.operator(RVOpenOutputDirectory.bl_idname, icon="DISK_DRIVE", text="")


# ------------------------------------------------------------------------
#    Helper
# ------------------------------------------------------------------------

def version_number(file_path, number, delimiter="_", min_lead=2):
    """Replace or add a version string by given number"""
    
    match = re.search(r'v(\d+)', file_path)
    if match:
        g = match.group(1)
        n = str(int(number)).zfill(len(g))
        return file_path.replace(match.group(0), "v{v}".format(v=n))
    
    else:
        lead_zeros = str(int(number)).zfill(min_lead)
        version = "{dl}v{lz}{dl}".format(dl=delimiter, lz=lead_zeros)
        ext = (".png",".jpg",".jpeg","jpg",".exr",".dpx",".tga",".tif",".tiff",".cin")
            
        if "#" in file_path:
            dash = file_path.find("#")
            head, tail = file_path[:dash], file_path[dash:]
            if head.endswith(delimiter):
                head = head.rstrip(delimiter)
            return "{h}{v}{t}".format(h=head, v=version, t=tail)
        
        elif file_path.endswith(ext):
            head, extension = os.path.splitext(file_path)
            if head.endswith(delimiter):
                head = head.rstrip(delimiter)
            return "{fp}{v}{ex}".format(fp=head, v=version[:-1], ex=extension)
            
        else:
            if file_path.endswith(delimiter):
                file_path = file_path.rstrip(delimiter)
            return "{fp}{v}".format(fp=file_path, v=version)
        
        
# ------------------------------------------------------------------------
#    Registration
# ------------------------------------------------------------------------

classes = (
    RVSettings,
    RVOpenOutputDirectory,
    RVOutNodesCleanup,
)

def register():
    from bpy.utils import register_class
    for cls in classes:
        register_class(cls)

    bpy.types.Scene.rv = bpy.props.PointerProperty(type=RVSettings)
    bpy.types.RENDER_PT_output.append(draw_rv)


def unregister():
    from bpy.utils import unregister_class
    for cls in reversed(classes):
        unregister_class(cls)
    
    bpy.types.RENDER_PT_output.remove(draw_rv)
    del bpy.types.Scene.rv

if __name__ == "__main__":
    register()
    

This is part of Loom as of version 0.7, an updated standalone gist is also available here.

$\endgroup$
3
  • 3
    $\begingroup$ great solution. It should be implemented in as a feature in blender! $\endgroup$
    – user1853
    Commented Mar 27, 2019 at 20:47
  • 1
    $\begingroup$ I think we can add it to this addon - remaining issue is that it would be nice adding a delimiter at the end of all input names initially to avoid confusing file names like render_v01XXXX.exr when rendering animations. Working on it, thanks for your feedback @cegaton $\endgroup$
    – p2or
    Commented Mar 27, 2019 at 21:06
  • 3
    $\begingroup$ this is amazing ! $\endgroup$
    – Fox
    Commented Mar 27, 2019 at 23:03
1
$\begingroup$

In the Properties panel of the File output node select Image/Render, click Add Input and it adds Render_001/Image_001socket. You just plug in to different socket every time you render. As you can see, the subpath name stays the same.
enter image description here

$\endgroup$
0
$\begingroup$

If it's an animation file names will already be enumerated. If it's not, you just go to the next keyframe before you rendering and it will not overwrite. If you don't want to move around on your timeline just select all the keyframes, slide one frame left and then the current frame one left.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .