# Insert video to sequence editor with python Script

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):

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():
bpy.utils.register_class(MyPanel)
bpy.utils.register_class(insertVideo)

def unregister():
bpy.utils.unregister_class(MyPanel)
bpy.utils.unregister_class(insertVideo)

if __name__ == "__main__":
register()


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 :

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_list = os.listdir(episode_path)
episode_sort = sorted(episode_list)
first_frame=0
last_frame=0
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
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
return{'FINISHED'}


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 -

bpy.ops.sequencer.movie_strip_add(filepath=video_file)


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'}

• Wow... it's work!!!! Thankyou sambler. You saved me... Hahaha – Aditya Dec 25 '16 at 2:52
• Now, i need to set the script. Because, the video always in the frame 0. Thanks for help sambler – 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:
bpy.context.scene.sequence_editor_create()