# selecting sequences in VSE via python

This script adds an effect color strip in the VSE then adds an image above it. I want to add a gamma cross strip so I can do a fade in. The trouble is there doesn't seem to be a way to select sequence strips by name. It seems odd that there isn't the ability to so something so simple. Is there a way to do it or some work around?

    import bpy
import os
import operator

class CustomPanel(bpy.types.Panel):
bl_label = "OpenSource::Classicism XL"
bl_space_type = "SEQUENCE_EDITOR"
bl_region_type = "UI"
bl_options = {'DEFAULT_CLOSED'}

def draw(self, context):
def add_label():
row = self.layout.row()
row.label("Intro Directory")

def add_import_button():
col = self.layout.split().column(align = True)
col.operator("sequencer.add_intro" , text= "Import")

add_label()

add_import_button()

class Add_Intro(bpy.types.Operator):
bl_idname = "sequencer.add_intro"
bl_label = "Add Intro"

def execute(self, context):

selection = []

def add_sequence_to_list():
selection.append(bpy.context.selected_sequences[0].name)

def select_strip(x):
bpy.context.scene.sequence_editor.sequences_all[image_file_list[0]].use_translation = True

def add_splash_screen():
start = 1
end = 90
channel = 2
directory = "C:\\Users\\...\\"
files = [{"name":"your_image.png"}]
bpy.ops.sequencer.image_strip_add(directory=directory, files=files, frame_start=start, frame_end=end, channel=channel)
add_sequence_to_list()

def add_background_color():
start = 1
end = 91
channel = 1

bpy.ops.sequencer.effect_strip_add(frame_start=start, frame_end=end, channel=channel, type='COLOR')
add_sequence_to_list()

def add_fade_in():
start = 1
end = 90
bpy.ops.sequencer.effect_strip_add(frame_start=1, frame_end=90, type='GAMMA_CROSS')

add_splash_screen()
add_background_color()
add_fade_in()

return {'FINISHED'}

def register():
bpy.utils.register_module(__name__)

def unregister():
bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
register()


## 1 Answer

Sequences API methods.

Can use API methods of class bpy.types.Sequences, from the instance scene.sequence_editor.sequences to add new strips to the VSE. As a "rule of thumb" I avoid using operators whenever possible. Using the API methods can reference the returned strip on creation, eg a new image strip: image_strip = sequences.new_image(...) removing the need to reference the strip by name at all.

Test script, adds an image strip on channel 1, a color strip on channel 2 and a gamma cross effect strip on channel 3. The color strips color is set to red. The gamma cross script uses the other two as input.

import bpy

context = bpy.context
scene = context.scene
sed = scene.sequence_editor
sequences = sed.sequences
# add an image strip
filepath = "/home/batfinger/Pictures/BGLTest.png"
frame_start = 1
frame_end = 90
# add an image strip.
image_strip = sequences.new_image("Image", filepath, 1, frame_start)
# give it a duration
image_strip.frame_final_end = frame_end

color_strip = sequences.new_effect("Color", 'COLOR', 2,
frame_start=frame_start,
frame_end=frame_end)

color_strip.color = (1, 0, 0)

gamma_strip = sequences.new_effect("GammaX", 'GAMMA_CROSS', 3,
frame_start=frame_start,
frame_end=frame_end,
seq1=color_strip,
seq2=image_strip)


Can reference a strip by name via sequences[name] I like to use sequences.get(name) as it will return None if a strip of that name does not exist.

If an image strip with same name is added twice, eg image_strip = sequences.new_image("Image", ...) again, the new strip will get the suffix "Image.001" naming. (Using the operator will do same thing, but with filename.) Can be sure of the name of new strip with image_strip.name.

An issue with your q script is what is image_file_list.

• This is great! I was looking for this in bpy.types but the auto completing didn't show that as an option even when I pressed s. Never thought of using capital S. It should exist in the autocomplete without pressing s first. image_file_list is from another script that I wrote that imports a sequence of images, centers and zooms it to screen. It worked so I thought maybe I could borrow some of that code. To no avail. – Urban Decay Feb 21 '18 at 2:05