1
$\begingroup$

I want the ability to color code strips in VSE. I got this code from a forum, but it does not work:

import bpy

strip = bpy.context.scene.sequence_editor.active_strip

strip.strip_color = (0.0, 0.0, 0.0)
#strip.use_strip_color = False

preset_subdir = "tracking_settings"

class AddPresetNodeColor(AddPresetBase, Operator):
    """Add or remove a Node Color Preset"""
    bl_idname = "node.node_color_preset_add"
    
preset_subdir = "node_color"

class SEQUENCER_PT_strip_color(SequencerButtonsPanel, Panel):
    bl_label = "Strip Color"
    bl_options = {'DEFAULT_CLOSED'}
    bl_category = "Strip"
    
    @classmethod
    def poll(cls, context):
        if not cls.has_sequencer(context):
            return False

        strip = act_strip(context)
        if not strip:
            return False

        return strip.type

    def draw_header(self, context):
        strip = act_strip(context)
        self.layout.prop(strip, "use_strip_color", text="")

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

        layout.enabled = strip.use_strip_color

        row = layout.row()
        row.prop(strip, "strip_color", text="color for the strips")
        
#class AddPresetStripColor(AddPresetBase, Operator):
    #"""Add or remove a Strip Color Preset"""
    #bl_idname = "strip.strip_color_preset_add"
    #bl_label = "Add Strip Color Preset"
    #preset_menu = "SEQUENCER_PT_strip_color_presets"

    #preset_defines = [
        #"strip = bpy.context.scene.sequence_editor.active_strip"
    #]

    #preset_values = [
        #"strip.strip_color",
        #"strip.use_strip_color"
    #]

    #preset_subdir = "strip_color"
    
class AddPresetInterfaceTheme(AddPresetBase, Operator):
    """Add or remove a theme preset"""
    bl_idname = "wm.interface_theme_preset_add"
    
AddPresetInterfaceTheme,
AddPresetKeyconfig,
AddPresetNodeColor,
#AddPresetStripColor,
AddPresetOperator,
AddPresetRender,
AddPresetSafeAreas,

from bl_ui.properties_grease_pencil_common import (
    AnnotationDataPanel,
)

from bl_ui.utils import PresetPanel
from rna_prop_ui import PropertyPanel

layout.label(text=iface_("Original frame range: %d-%d (%d)") % (sta, end, end - sta + 1), translate=False)

class SEQUENCER_PT_strip_color_presets(PresetPanel, Panel): #apparently this class isnt needed.
    """Predefined node color"""
    bl_label = "Color Presets"
    preset_subdir = "strip_color"
    preset_operator = "script.execute_preset"
    preset_add_operator = "strip.strip_color_preset_add"

class SEQUENCER_PT_strip_color(SequencerButtonsPanel, Panel):
    bl_label = "strip Color"
    bl_options = {'DEFAULT_CLOSED'}
    bl_category = "Strip"
    
    @classmethod
    def poll(cls, context):
        if not cls.has_sequencer(context):
            return False

        strip = act_strip(context)
        if not strip:
            return False

        return strip.type

    def draw_header(self, context):
        strip = act_strip(context)
        self.layout.prop(strip, "use_strip_color", text="")

    #def draw_header_preset(self, _context): #apparently not needed
        
SEQUENCER_PT_strip_color_presets.draw_panel_header(self.layout)

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

        layout.enabled = strip.use_strip_color

        row = layout.row()
        row.prop(strip, "strip_color", text="")


class SEQUENCER_PT_time(SequencerButtonsPanel, Panel):
    bl_label = "Time"
    bl_options = {'DEFAULT_CLOSED'}
    
SEQUENCER_PT_effect_text_layout,
SEQUENCER_PT_effect_text_style_shadow,
#SEQUENCER_PT_strip_color_presets,
SEQUENCER_PT_color, #possibly remove
SEQUENCER_PT_time,
SEQUENCER_PT_source,

if (scene->ed) {
        Sequence *seq;
        SEQ_BEGIN (scene->ed, seq) {
          seq->flag &= ~(SEQ_FLAG_UNUSED_6 | SEQ_FLAG_UNUSED_19 | #possibly remove
                         SEQ_FLAG_UNUSED_21);
          if (seq->type == SEQ_TYPE_SPEED) {
            SpeedControlVars *s = (SpeedControlVars *)seq->effectdata;
            
unsigned char blendcol[3];
  SolidColorVars *colvars = (SolidColorVars *)seq->effectdata;

    if (seq->flag & SEQ_USE_STRIP_COLOR && seq->type != SEQ_TYPE_COLOR){
        rgb_float_to_uchar(col, seq->strip_color);
        return;
    }

  switch (seq->type) {
    case SEQ_TYPE_IMAGE:
      UI_GetThemeColor3ubv(TH_SEQ_IMAGE, col);
      
/** SEQ_NAME_MAXSTR - name, set by default and needs to be unique, for RNA paths. */
  char name[64];

  /* Custom Strip Color */
  #float strip_color[3];
  
char _pad4[4];

  /** Flags bitmap (see below) and the type of sequence. */
  int flag, type;
  /** The length of the contents of this strip - before handles are applied. */
  
SEQ_USE_PROXY = (1 << 15),
  SEQ_USE_TRANSFORM = (1 << 16),
  SEQ_USE_CROP = (1 << 17),
  SEQ_USE_STRIP_COLOR = (1 << 18),
  SEQ_FLAG_UNUSED_19 = (1 << 19), /* cleared */
  SEQ_FLAG_UNUSED_21 = (1 << 21), /* cleared */
  
RNA_def_property_update(
      prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_invalidate_preprocessed_update");

  /* Custom Strip Color */ #possibly ername strip color as "use ui_custom_strip_color"
  prop = RNA_def_property(srna, "use_strip_color", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_USE_STRIP_COLOR);
  RNA_def_property_boolean_default(prop, 0);
  RNA_def_property_ui_text(prop, "Enable custom strip color", "Uses custom strip color if enabled");
  RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, NULL);
  
static const float default_strip_color[] = {0.f, 0.f, 0.f};
  prop = RNA_def_property(srna, "strip_color", PROP_FLOAT, PROP_COLOR_GAMMA);
  RNA_def_property_float_sdna(prop, NULL, "strip_color");
  RNA_def_property_array(prop, 3);
  RNA_def_property_float_array_default(prop, default_strip_color);
  
RNA_def_property_ui_text(prop, "Strip Color", "Custom Strip color");
  RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, NULL);

  /* blending */
  prop = RNA_def_property(srna, "blend_type", PROP_ENUM, PROP_NONE);
  RNA_def_property_enum_sdna(prop, NULL, "blend_mode");
  RNA_def_property_enum_items(prop, blend_mode_items);

Q: Any suggestions to make it work?

$\endgroup$
1
2
$\begingroup$

A work-around, suggested by David McSween, is to add a color strip beneath the strip you want to color and group them together (Ctrl+G). That way, you'll see a small colored bar within the strip. Because the color strip is underneath and by default replaced with the original strip, nothing will change in the viewport.

The code above seems to come from a suggested patch. It's still in revision (from 2018) and I don't think it's wise to install it at this moment. Maybe, you can inquire with the author?

$\endgroup$

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.