2
$\begingroup$

I have a main meta-strip which contains a sub meta-strip. In the sub meta-strip, there is a regular sequence named BaseSequence. I want to write a script to add some effect strips(e.g. Transform strip) for that BaseSequence.

Here is my idea:

  1. select the main meta strip and call toggle function to enter it.
  2. select the sub meta strip and call toggle function to enter it.
  3. select the BaseSequence and add Transform effect strip.
  4. leave the sub meta strip.
  5. leave the main meta strip.

Here is my code:

import bpy

class SimpleOperator(bpy.types.Operator):
    bl_idname = "sequencer.simple_operator"
    bl_label = "Simple Operator"

    @classmethod
    def poll(cls, context):
        return len(context.selected_sequences) == 1

    def execute(self, context):
        main_metastrip = context.selected_sequences[0]
        sub_metastrip = main_metastrip.sequences.get("SubMetaStrip")
        base_sequence = sub_metastrip.sequences.get("BaseSequence")
        
        # enter main meta strip
        bpy.ops.sequencer.meta_toggle() 
        bpy.ops.sequencer.select_all(action='DESELECT')
        
        # select sub meta strip
        sub_metastrip.select = True
        
        # enter sub meta strip(**don't work here**)
        bpy.ops.sequencer.meta_toggle() 
        bpy.ops.sequencer.select_all(action='DESELECT')
        
        # return {'FINISHED'} # uncomment this to see the intermediate result
        
        # select base sequence
        base_sequence.select = True
        
        # add efffect strip
        bpy.ops.sequencer.effect_strip_add(type='TRANSFORM')
        
        # leave sub meta strip
        bpy.ops.sequencer.select_all(action='DESELECT')
        bpy.ops.sequencer.meta_toggle() 
        
        # leave main meta strip
        bpy.ops.sequencer.select_all(action='DESELECT')
        bpy.ops.sequencer.meta_toggle() 
        
        return {'FINISHED'}


def register():
    bpy.utils.register_class(SimpleOperator)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
    register()

    bpy.ops.sequencer.simple_operator()

The problem is it fails at step 2. I can't enter the sub meta strip. In fact, it turns out leaving the main meta strip.

I found that when i call sub_metastrip.select = True, there is an orange outline around the sub meta strip.

the orange outline

Now i call bpy.ops.sequencer.meta_toggle(). I can't enter the sub meta strip. But i select the sub meta strip by click using my mouse, i see a white outline around the sub meta strip which works fine after calling bpy.ops.sequencer.meta_toggle(). That is what i want.

the white outline

I think that's the problem. I can't select the sub meta strip with white outline using python. I wonder how to enter the sub meta strip using python. In other words, how to select a meta strip inside another meta strip in a proper way using python?

Thanks.

Here is the blend file. Btw, I'm using blender 2.91.0.

Edit: Thank @tintwotin and This question. I found the solution.

# make it selected and active
sub_metastrip.select = True
context.scene.sequence_editor.active_strip = sub_metastrip
$\endgroup$
3
  • $\begingroup$ Orange outline means selected, but not active. White outline means selected and active. White text and no outline means active, but not selected. Active means ex. this strip's properties are shown in the sidebar. $\endgroup$
    – tintwotin
    Feb 1, 2021 at 6:47
  • $\begingroup$ And this strip will have applied changes, so try .active = True $\endgroup$
    – tintwotin
    Feb 1, 2021 at 6:53
  • $\begingroup$ @tintwotin Thanks for your help. I try sub_metastrip.active = True and get an error. The strip doesn't have an attribute named 'active'. Your words remind me of the difference between 'selected' and 'active'. I search for a while and get the solution finally. Thanks again. $\endgroup$ Feb 1, 2021 at 8:51

0

You must log in to answer this question.

Browse other questions tagged .