I’m trying to write a script to import image sequences - specifically, to take a bunch of renders in this directory structure:
renders ⌄
scene_01 ⌄
image0001.png
image0002.png
...
scene_02 ⌄
image0001.png
image0002.png
...
scene_03 ⌄
image0001.png
image0002.png
...
and import them into a sequence in the VSE, one after the other.
[scene_01 strip][scene_02 strip][scene_03 strip]
But I’m stuck at a very basic level - I can’t get the right context for the image_strip_add()
operator. Here’s the current script:
import bpy
import os
renders_folder = bpy.path.abspath("//renders")
rendered_scenes = sorted(os.listdir(renders_folder))
for scene in rendered_scenes:
folder = renders_folder + '/' + scene
images = []
for image in sorted(os.listdir(folder)):
images.append({"name": image })
bpy.ops.sequencer.image_strip_add(
directory=folder,
files=images,
show_multiview=False,
channel=1)
The error message I get is:
Operator bpy.ops.sequencer.image_strip_add.poll() failed, context is incorrect
I don’t know which aspect of the context is incorrect, or how I can fix it. Is there a way to get more detailed information?
I don’t know how to properly get a thorough view of the current context, but I can print a bunch of values:
area: None
blend_data: <bpy_struct, BlendData at 0x7f76f6315c08>
collection: <bpy_struct, Collection("Master Collection") at 0x7f76f525bf48>
engine: CYCLES
gizmo_group: None
layer_collection: <bpy_struct, LayerCollection("Master Collection") at 0x7f76f5235578>
mode: OBJECT
region: None
scene: <bpy_struct, Scene("EDIT") at 0x7f76f5248808>
screen: <bpy_struct, Screen("Default.025") at 0x7f76f632a908>
space_data: None
view_layer: <bpy_struct, ViewLayer("View Layer") at 0x7f76f525be08>
window: <bpy_struct, Window at 0x7f76f6323408>
window_manager: <bpy_struct, WindowManager("WinMan") at 0x7f771a36d008>
workspace: <bpy_struct, WorkSpace("Video Editing") at 0x7f76f632a048>
workspace.name: Video Editing
Most of the stackexchange discussions suggested setting the active area to the sequence editor, but I haven’t found a way to set the active area yet, all the old solutions from a few years ago don’t seem to work anymore.
I don’t need to run the blender GUI, I could run this once in headless mode and then save the file if that would be easier? Does that change the process of adding image sequence strips?
I am just starting out with blender scripting, so I may be missing something obvious. I’ve googled myself to exhaustion though!