i want to create a button for insert a video to video sequence editor. i have written a script :

import bpy, os

class insertVideo(bpy.types.Operator):
    bl_idname = "scene.invideo"
    bl_label = "Insert Video"

    def execute(self, context):
        episode_path = "F:\\Dokumen\\Target\\Develop Apps\\addon_blender\\tes"

class MyPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "My Tools"
    bl_idname = "my.panel"
    bl_space_type = 'SEQUENCE_EDITOR'
    bl_region_type = 'UI'

    def draw(self, context):
        layout = self.layout

        obj = context.object

        row = layout.row()
        row.label(text="Movie File")       
        row = layout.row()
        row.operator("scene.invideo", text="Insert Video")

def register():

def unregister():

if __name__ == "__main__":

In episode_path = "F:\\Dokumen\\Target\\Develop Apps\\addon_blender\\tes"

I have 3 videos :

  1. file1.mov
  2. file2.mov
  3. file3.mov

I hope, when i click this button :


It will insert all videos from episode_path. But, i have a problem. When i click the button, it always show error :

enter image description here

Maybe you can help me, What did i miss? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@cmomoney @sambler Thanks for your answer guys. Finally, i can finish my first addon in blender. I add this in execute function :

def execute(self, context):
        episode_path = bpy.path.abspath("F:\\Dokumen\\Target\\Develop Apps\\addon_blender\\tes")
        episode_list = os.listdir(episode_path)
        episode_sort = sorted(episode_list)
        for v in [f for f in episode_sort if f.endswith('.mov')]:
            movs = os.path.join(episode_path,v)
            start_frame = last_frame+first_frame
            bpy.ops.sequencer.movie_strip_add(filepath=movs, frame_start=start_frame, channel=1)
            first_frame = bpy.context.scene.sequence_editor.sequences_all[v].frame_start
            last_frame = bpy.context.scene.sequence_editor.sequences_all[v].frame_final_duration

Thanks for your help guys


When invoking an operator in python, there are three positional arguments that are generic to all operators, all other arguments that pass settings specific to the operator must use keyword arguments.

So to call the operator you should use -


Note that movie_strip_add will add one video file as a strip, so to add a directory of movies you will want to use a loop.

def execute(self, context):
    episode_path = "/path/to/videos/"
    for v in [f for f in os.listdir(episode_path) if f.endswith('.mov')]:
    return {'FINISHED'}
|improve this answer|||||
  • $\begingroup$ Wow... it's work!!!! Thankyou sambler. You saved me... Hahaha $\endgroup$ – Aditya Dec 25 '16 at 2:52
  • $\begingroup$ Now, i need to set the script. Because, the video always in the frame 0. Thanks for help sambler $\endgroup$ – Aditya Dec 25 '16 at 2:58

You could skip using ops altogether: new_movie(name, filepath, channel, frame_start)

def execute(self, context):
    #create sequence_editor if none exists
    if not bpy.context.scene.sequence_editor:
    episode_path = "F:\\Dokumen\\Target\\Develop Apps\\addon_blender\\tes"
    movs = [os.path.join(path,v) for v in os.listdir(episode_path) if v.endswith('.mov')]
    for i in range(len(movs)):
        bpy.context.scene.sequence_editor.sequences.new_movie(os.path.basename(movs[i]), movs[i], i, 1)

Doing it this way also gives you more control, like name and what channel and frame for placement.

|improve this answer|||||
  • $\begingroup$ Hi cmomoney, i follow your tips but... uhmmm. this script doesn't work... $\endgroup$ – Aditya Dec 25 '16 at 3:08
  • $\begingroup$ Maybe you can explain, why you define variable v in movs variable. Because, it's always error. error : variable v is not define. $\endgroup$ – Aditya Dec 25 '16 at 3:26
  • $\begingroup$ So, i modified to this : for v in [f for f in os.listdir(episode_path) if f.endswith('.mov')]: movs = os.path.join(episode_path,v) for i in range(len(movs)): bpy.context.scene.sequence_editor.sequences.new_movie(os.path.basename(movs[i]), movs[i], i, 1) $\endgroup$ – Aditya Dec 25 '16 at 3:31
  • $\begingroup$ Wow, looks messy.. and, i got this error : sequences.new_movie: unable to open movie file $\endgroup$ – Aditya Dec 25 '16 at 3:32
  • $\begingroup$ v is the variable for the filename found in the episode path that ends with '.mov'. Its joined together with the path and added to the movs list. $\endgroup$ – cmomoney Dec 25 '16 at 4:50

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.