2
$\begingroup$

Is it possible to set the scene name in the output properties in the VSE to the scene name?

On blenderartists.org I read that %S should be the scene name. When I enter this in the output section as /path/to/file/%S.mp4 the file is named "%S.mp4". I am probably doing this wrong, but I wonder if this even possible to name the file in this location.

What I want to do:
I use blender to create short animations for presentations. To be able to continue with the animation where the last scene stopped I copy the scene and delete everything I do not need. The filename is copied over. The filename is not changed so when you have more than one scene, the output of the second scene will overwrite the one of the first scene when you forget to change the filename.

$\endgroup$
9
  • 1
    $\begingroup$ that's a very good question. in the documentation it mentions only about the #### syntax but nothing about %s or other syntax. I wonder if anyone knows something. $\endgroup$ Jul 19 at 7:37
  • $\begingroup$ Have you tried to look for add-ons doing what you need? blenderdepot.netlify.app/… $\endgroup$
    – tintwotin
    Jul 28 at 8:22
  • $\begingroup$ @tintwotin at first I thought %S was a feature in blender that is broken now but then I found out it was from the vray-blender addon. and I found this addon. I was hoping this feature was a built-in in blender. i guess not. so blender's file output only supports the # syntax right? then I guess this issue is "solved" $\endgroup$ Jul 28 at 14:38
  • $\begingroup$ Have you tried setting the output to '/path/to/file/' + bpy.context.scene.name + '.mp4' ? $\endgroup$ Jul 28 at 20:45
  • 1
    $\begingroup$ Yeah addon is fine. I just wanted to confirm if the Output Name field really only accepted the # syntax with no other possible syntaxes. But I think the dev team really ought to consider changing this field to accept python expressions XD $\endgroup$ Jul 28 at 21:27

1 Answer 1

3
+50
$\begingroup$

This can be done with Python by setting the context.scene.render.filepath setting. Here's an example mini addon that does this by putting a button called "Set Render Path" in the output panel of the properties editor. It works by getting the file directory that the user has already set to render to and then replacing the name of the file with the name of the scene (bpy.context.scene.name).

import bpy
import os

def get_file_directory_from_path(filepath):
    return os.path.dirname(bpy.path.abspath(filepath)) + os.path.sep

class ButtonPanel(bpy.types.Panel):
    bl_label = "Set Path Panel"
    bl_idname = "SCENE_PT_layout"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "output"

    def draw(self, context):
        layout = self.layout
        layout.operator("render.set_render_path_and_render")

class SetRenderPathThenRender(bpy.types.Operator):
    """This appears in the tooltip of the operator and in the generated docs"""
    bl_idname = "render.set_render_path_and_render"
    bl_label = "Set Render Path"

    def execute(self, context):
        context.scene.render.filepath = os.path.join(
            get_file_directory_from_path(
                context.scene.render.filepath
            ),
            bpy.context.scene.name + '.mp4'
        )
#        bpy.ops.render.render(animation=True)
        return {'FINISHED'}

def register():
    bpy.utils.register_class(ButtonPanel)
    bpy.utils.register_class(SetRenderPathThenRender)


def unregister():
    bpy.utils.unregister_class(SetRenderPathThenRender)
    bpy.utils.unregister_class(ButtonPanel)


if __name__ == "__main__":
    register()

This assumes that the file extension has already been set to .mp4 by the user. Optionally, if you'd like to render after clicking this button, you can uncomment the line with bpy.ops.render.render(animation=True).

$\endgroup$
2
  • 1
    $\begingroup$ yes this is a good solution. since the user has to press the render button anyway, they could press another "render" button in the addon that automatically set's the filepath before rendering :) thanks for sharing! $\endgroup$ Jul 31 at 2:29
  • $\begingroup$ @HarryMcKenzie Yeah! Thanks :)) $\endgroup$ Jul 31 at 2:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.