Add images with bpy.ops.sequencer.image_strip_add

(mythcat) #1

I want to make a script to add all images from folder : C: mp into Video Sequence Editor


I search on forum and internet and the result is just this:

How can I do that ?

Thank you. Best regards.

(mythcat) #2

I try this source of code but I got errors:

import bpy
import os

dir="C:/tmp/"  #not include files
dirproxy="C:/tmp/" #including proxy file

print ("aaa")
for i in os.listdir(dir):
    bpy.ops.sequencer.image_strip_add( \
        directory = dir, \
        channel=0, \

This is the output:

{'name': '0001.png'}
[{'name': '0001.png'}]

Traceback (most recent call last):
  File "<blender_console>", line 12, in <module>
  File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\modules\bpy\", line 189, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.sequencer.image_strip_add.poll() failed, context is incorrect

(eceathar) #3


I don’t know if you solve your problem,
but I had the same problem and the answer was to change the area context

area = bpy.context.area
old_type = area.type
area.type = 'SEQUENCE_EDITOR'
# call the image_strip_add here and other functions
area.type = old_type 

(thanks to

(mythcat) #4

@eceathar Thank you for reply.

I used dir=os.path.abspath(“C:/tmp/”) is a good way to use paths.

Also I have the 2.79a version now.
I cannot read files in Blender python (but same source code works fine on python 3.6.x).
You can see the bug I open
About your idea with context then that just change area window from python text area to SEQUENCE_EDITOR
The main problem to add images is the function: image_strip_add.poll()

(Januz) #5

Eceathar’s answer is right. image_strip_add.poll() is failing because the context is not what the operator expects. Like Sergey says in the bug you linked, you should use a “low-level” function instead of an operator. In this case: scene.sequence_editor.sequences.new_image()

The file reading issue is a permission issue, probably Blender (or Blender’s python interpreter) doesn’t have the permissions to read files from c: mp. Can you read files from other folders?
If you want to use the system’s temp folder consider using the tempfile module

(mythcat) #6

I need a good example versus API 2.79a on my issue.
I understand the context issue and the error info - is failing because the context , the result is not working.
I don’t make changes on OS to Blender 3D - is a default install, but
my python 3.6.x install (not Blender 3D python) is running good , see:
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)]
on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import os
>>> dir=os.path.abspath(“C:/tmp/”)
>>> for i in os.listdir(dir):


the bug has close and refer a function on API not : BlendDataImages(bpy_struct) - version 2.79
your reply use the version 2.78 scene.sequence_editor.sequences.new_image()