The bpy.ops.sequencer.image_strip_add() operator can add multiple images as a single strip. Here's a simple example that takes directory C:\Users\xxxx\Desktop\test\ containing 5 images of the format image_####.png and imports them as a sequence. You need to use the proper context, which is SEQUENCE_EDITOR, in order to use the bpy.ops.sequencer.image_strip_add command:
import bpy
directory = r"C:\Users\xxxx\Desktop\test"
prefix = "image_" #prefix in image_0001.png
frame_start = 1
frame_end = 5
files = []
for frame in range(frame_start, frame_end + 1):
files.append({"name":f"{prefix}{frame:04d}.png"})
area_type = 'SEQUENCE_EDITOR'
areas = [area for area in bpy.context.window.screen.areas if area.type == area_type]
with bpy.context.temp_override(
window=bpy.context.window,
area=areas[0],
regions=[region for region in areas[0].regions if region.type == 'WINDOW'][0],
screen=bpy.context.window.screen
):
bpy.ops.sequencer.image_strip_add(
directory=directory,
files=files,
relative_path=True,
show_multiview=False,
frame_start=frame_start,
frame_end=frame_end,
channel=1,
fit_method='FIT'
)
On the other hand, the new_image() method is designed to create a new image sequence strip for a single image file. It does not have the ability to automatically combine multiple images into a single strip so you will end up with 5 image sequences:
import bpy
import os
directory = r"C:\Users\xxxx\Desktop\test"
prefix = "image_" #prefix in image_0001.png
frame_start = 1
frame_end = 5
for frame in range(frame_start, frame_end + 1):
filename = f"{prefix}{str(frame).zfill(4)}.png"
seq = bpy.data.scenes[0].sequence_editor.sequences.new_image(
name = filename,
filepath = os.path.join(directory, filename),
channel = 1,
frame_start = frame,
fit_method = 'ORIGINAL'
)
bpy.context.area.ui_type = 'SEQUENCE_EDITOR'at the beginning of the script. No other way to do it :) – Harry McKenzie Feb 25 '23 at 02:19