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"
bpy.ops.sequencer.movie_strip_add(episode_path)
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()
In episode_path = "F:\\Dokumen\\Target\\Develop Apps\\addon_blender\\tes"
I have 3 videos :
- file1.mov
- file2.mov
- 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_path = bpy.path.abspath("F:\\Dokumen\\Target\\Develop Apps\\addon_blender\\tes")
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
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
return{'FINISHED'}
Thanks for your help guys