Edit strip with compositor


(peddie) #1

Hi!

I want to create a addon which makes it easier to edit stripes from the sequencer with the compositor.

This is what I want to do:
Add a button in the Sequencer “Edit strip(s) in Compositor”, when pressed call the operator.
For each selected strip
if strip is a movie clip
Create new scene with same name as strip
Edit the scene endFrame to match strip length
Create a composite with the moviestrip file as input
Go back to original scene and add/position the newly created scene ontop of the moviestrip.

Script without GUI (select a moviestrip in the sequencer and run script)

import bpy
# Get selected strips
sel_strips = bpy.context.selected_sequences

# Get current scene
cur_scene = bpy.context.scene

# Loop selected strips                         
for strip in sel_strips:

  # Check if strip is a movie
  if (strip.type == 'MOVIE'):
    # Create a new scene
    new_scene = bpy.ops.scene.new(type='EMPTY')
    
    # Name it after the moviestrip
    bpy.context.scene.name = strip.name
    
    # Change scene EndFrame to match strip             
    bpy.context.scene.frame_end = strip.frame_final_end
    
    # Setup nodes
    bpy.context.scene.use_nodes = True
    tree = bpy.context.scene.node_tree
    
    # Clear default nodes
    for n in tree.nodes:
        tree.nodes.remove(n)
        
    # Create input node
    rl = tree.nodes.new('IMAGE')      
    rl.location = 0,0
    # Add strip path (NOT WORKING)
    rl.layer = strip.filepath

    # create output node
    comp = tree.nodes.new('COMPOSITE')   
    comp.location = 400,0

    # Link nodes
    links = tree.links
    link = links.new(rl.outputs[0],comp.inputs[0])    
    
    # Change current scene to original (NOT WORKING)                                          
    bpy.context.screen.scene = cur_scene
    bpy.context.screen.scene.update() 
    
    # Add newly created scene                                           
    bpy.ops.sequencer.scene_strip_add(frame_start=strip.frame_start, channel=strip.channel + 1, replace_sel=False, scene=strip.name)
    
    # Edit the strip length to match original strip                                                  
    bpy.context.sequences[0].frame_final_end = strip.frame_final_end

This is what I have:

import bpy
 
class StripCompositorPanel(bpy.types.Panel):
  bl_label = "Edit strip with Compositor"
  bl_space_type = "SEQUENCE_EDITOR"
  bl_region_type = "UI"
 
def draw(self, context):
  layout = self.layout
   
  row = layout.row()
  row.operator( "bpt.stripcompositor_op" )
  
 
class StripCompositor(bpy.types.Operator):
  bl_idname = "bpt.stripcompositor_op"
  bl_label = "Edit strip(s) with Compositor"
  def execute(self, context):
    # Get selected strips
    sel_strips = bpy.context.selected_sequences

    # Get current scene
    cur_scene = bpy.context.scene

    # Loop selected strips                         
    for strip in sel_strips:

      # Check if strip is a movie
      if (strip.type == 'MOVIE'):
        # Create a new scene
        new_scene = bpy.ops.scene.new(type='EMPTY')
        
        # Name it after the moviestrip
        bpy.context.scene.name = strip.name
        
        # Change scene EndFrame to match strip             
        bpy.context.scene.frame_end = strip.frame_final_end
        
        # Setup nodes
        bpy.context.scene.use_nodes = True
        tree = bpy.context.scene.node_tree
        
        # Clear default nodes
        for n in tree.nodes:
            tree.nodes.remove(n)
            
        # Create input node
        rl = tree.nodes.new('IMAGE')      
        rl.location = 0,0
        # Add strip path (NOT WORKING)
        rl.layer = strip.filepath

        # Create output node
        comp = tree.nodes.new('COMPOSITE')   
        comp.location = 400,0

        # Link nodes
        links = tree.links
        link = links.new(rl.outputs[0],comp.inputs[0])    
        
        # Change current scene to original (NOT WORKING)                                          
        bpy.context.screen.scene = cur_scene
        bpy.context.screen.scene.update() 
        
        # Add newly created scene                                           
        bpy.ops.sequencer.scene_strip_add(frame_start=strip.frame_start, channel=strip.channel + 1, replace_sel=False, scene=strip.name)
        
        # Edit the strip length to match original strip                                                  
        bpy.context.sequences[0].frame_final_end = strip.frame_final_end
    return {'FINISHED'}
 
 
def register():
  bpy.utils.register_class( StripCompositor )
  bpy.utils.register_class( StripCompositorPanel )
 
def unregister():
  bpy.utils.register_class( StripCompositor )
  bpy.utils.register_class( StripCompositorPanel )
 
if __name__ == '__main__':
  register() 

This is my problems:
GUI: Button is not visible in the UI.

Sequencer: Scenes gets added in the newly created scene(itself) instead of the original, containing the moviestrip.

Compositor: I don’t know how to link the input node with the moviecllip

Any help on this would be appreciated!


(3pointEdit) #2

Reminds me a little of Carlos’s Hipostatiator script but that makes other scenes to use multiple VSEs.

There maybe some cross over between the two ideas, and Strip-to nodes-to strip is an workflow I have wanted to see for ages. Perhaps you could even bundle the original strip and it’s node child strip, together in a Meta strip. So it doesn’t loose sync. Although that would make de-activating Nodes (for speed) difficult.

Good luck and I hope this script (if it works out ok) is accepted into trunk distribution, as so many languish as the API matures :frowning: Like Carlos’s Jump-to-cut script. It is great but won’t function unless maintained.


(peddie) #3

Thank you David!

I also think this workflow could be extremely powerful, but unfortunately I’m stuck at my 3 points above and I really need some help with those to continue my proposal.


(peddie) #4

I can’t figure it out, it’s like this:

bpy.context.screen.scene = cur_scene
bpy.context.screen.scene.update()

gets executed after this:

bpy.ops.sequencer.scene_strip_add(frame_start=strip.frame_start, channel=strip.channel + 1, replace_sel=False, scene=strip.name)

Even though it comes earlier in the script??


(Numarul7) #5

peddie go to freenode.irc channel #blendercoders , use webfreenode irc or other type of clients. On that channel you can ask same question here about your script and someone of the developers can help you.


(peddie) #6

Thanks Numarul7, although isn’t this the correct forum for python support? I logged in to #blendercoders but I got no response from anyone (maybe it’s the time difference).


(peddie) #7

Bumping this since I think it’s an important feature and I don’t know how to solve the issues above.


(3pointEdit) #8

You could try asking about the GUI issue separately.

To access the movie clip (from VSE) I don’t think it appears as an asset to Nodes. When I add clips to Nodes I always have to search for them again. Unless the movie has been added as a texture, then it is available throughout Blender.


(Sleeper) #9

I don’t know if this will be any more successful but the freenode irc channel for python help is #blenderpython.


(TMW) #10

Hi,

This looks good, where is the button supposed to appear in the VSE UI?

Thanks
Tom


(TMW) #11

Hi,

I don’t know if this helps:

import bpy
 
class CompPanel(bpy.types.Panel):
    bl_label = "Strip Comp"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"
 
    def draw(self, context):
        scn = bpy.context.scene
        layout = self.layout
        row = layout.row()
        col = row.column()
 
 
        col.operator( "bpt.sample_op" )
 
 
class CompOperator(bpy.types.Operator):
 
    bl_idname = "bpt.sample_op"
    bl_label = "Strip Comp"
 
    def invoke(self, context, event ):
 
        # Get selected strips
        sel_strips = bpy.context.selected_sequences
        # Get current scene
        cur_scene = bpy.context.scene
        # Loop selected strips                         
        for strip in sel_strips:
            # Check if strip is a movie
            if (strip.type == 'MOVIE'):
                # Create a new scene
                new_scene = bpy.ops.scene.new(type='EMPTY')
 
                # Name it after the moviestrip
                bpy.context.scene.name = strip.name
 
                # Change scene EndFrame to match strip             
                bpy.context.scene.frame_end = strip.frame_final_end
 
                # Setup nodes
                bpy.context.scene.use_nodes = True
                tree = bpy.context.scene.node_tree
 
                # Clear default nodes
                for n in tree.nodes:
                    tree.nodes.remove(n)
 
                # Create input node
                rl = tree.nodes.new('IMAGE')      
                rl.location = 0,0
                # Add strip path (NOT WORKING)
                rl.layer = strip.filepath
                # Create output node
                comp = tree.nodes.new('COMPOSITE')   
                comp.location = 400,0
                # Link nodes
                links = tree.links
                link = links.new(rl.outputs[0],comp.inputs[0])    
 
                # Change current scene to original (NOT WORKING)                                          
                bpy.context.screen.scene = cur_scene
                bpy.context.screen.scene.update() 
 
                # Add newly created scene                                           
                bpy.ops.sequencer.scene_strip_add(frame_start=strip.frame_start, channel=strip.channel + 1, replace_sel=False, scene=strip.name)
 
                # Edit the strip length to match original strip                                                  
                bpy.context.sequences[0].frame_final_end = strip.frame_final_end
 
                self.report( "INFO", "RUN" )
 
                return {'FINISHED'}
 
 
def register():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
def unregister():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
if __name__ == "__main__":
    register()
 

It has the button in the objects tab (thats all I could get to work) and it adds the node, and says it can’t find the clip (in the new scene).

Thanks
Tom


(TMW) #12

Sorry, got it in the Render Panel now, I don’t now how to do the VSE.

import bpy
 
class CompPanel(bpy.types.Panel):
    bl_label = "Strip Comp"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "render"
 
    def draw(self, context):
        scn = bpy.context.scene
        layout = self.layout
        row = layout.row()
        col = row.column()
 
 
        col.operator( "bpt.sample_op" )
 
 
class CompOperator(bpy.types.Operator):
 
    bl_idname = "bpt.sample_op"
    bl_label = "Strip Comp"
 
    def invoke(self, context, event ):
        
        # Get selected strips
        sel_strips = bpy.context.selected_sequences
        # Get current scene
        cur_scene = bpy.context.scene
        # Loop selected strips                         
        for strip in sel_strips:
            # Check if strip is a movie
            if (strip.type == 'MOVIE'):
                # Create a new scene
                new_scene = bpy.ops.scene.new(type='EMPTY')
        
                # Name it after the moviestrip
                bpy.context.scene.name = strip.name
        
                # Change scene EndFrame to match strip             
                bpy.context.scene.frame_end = strip.frame_final_end
        
                # Setup nodes
                bpy.context.scene.use_nodes = True
                tree = bpy.context.scene.node_tree
        
                # Clear default nodes
                for n in tree.nodes:
                    tree.nodes.remove(n)
            
                # Create input node
                rl = tree.nodes.new('IMAGE')      
                rl.location = 0,0
                # Add strip path (NOT WORKING)
                rl.layer = strip.filepath
                # Create output node
                comp = tree.nodes.new('COMPOSITE')   
                comp.location = 400,0
                # Link nodes
                links = tree.links
                link = links.new(rl.outputs[0],comp.inputs[0])    
        
                # Change current scene to original (NOT WORKING)                                          
                bpy.context.screen.scene = cur_scene
                bpy.context.screen.scene.update() 
        
                # Add newly created scene                                           
                bpy.ops.sequencer.scene_strip_add(frame_start=strip.frame_start, channel=strip.channel + 1, replace_sel=False, scene=strip.name)
        
                # Edit the strip length to match original strip                                                  
                bpy.context.sequences[0].frame_final_end = strip.frame_final_end
                
                self.report( "INFO", "RUN" )
    
                return {'FINISHED'}
 
 
def register():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
def unregister():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
if __name__ == "__main__":
    register()
 

Thanks
Tom


(peddie) #13

Hi and thanks for the replies.

I have updated the GUI and code which now adds a working button in the properties panel of a strip (thanks to TMW):

import bpy
 
class CompPanel(bpy.types.Panel):
    bl_space_type = "SEQUENCE_EDITOR"
    bl_region_type = "UI"
    bl_label = "Edit strip with Compositor"
 
    def draw(self, context):
        scn = bpy.context.scene
        layout = self.layout
        row = layout.row()
        col = row.column()
 
 
        col.operator( "bpt.sample_op" )
 
 
class CompOperator(bpy.types.Operator):
 
    bl_idname = "bpt.sample_op"
    bl_label = "Edit strip with Compositor"
 
    def invoke(self, context, event ):
        
            import bpy
            # Get selected strips
            sel_strips = bpy.context.selected_sequences
            
            # Get current scene
            cur_scene = bpy.context.scene
            
            # Loop selected strips                         
            for strip in sel_strips:
            
              # Check if strip is a movie
              if (strip.type == 'MOVIE'):
                # Create a new scene
                new_scene = bpy.ops.scene.new(type='EMPTY')
                
                # Name it after the moviestrip
                bpy.context.scene.name = strip.name
                
                # Change scene EndFrame to match strip             
                bpy.context.scene.frame_end = strip.frame_final_end
                
                # Setup nodes
                bpy.context.scene.use_nodes = True
                tree = bpy.context.scene.node_tree
                
                # Clear default nodes
                for n in tree.nodes:
                    tree.nodes.remove(n)
                    
                # Create input node
                rl = tree.nodes.new('IMAGE')      
                rl.location = 0,0
                # Add strip path (NOT WORKING)
                # rl.layer = strip.filepath
            
                # create output node
                comp = tree.nodes.new('COMPOSITE')   
                comp.location = 400,0
            
                # Link nodes
                links = tree.links
                link = links.new(rl.outputs[0],comp.inputs[0])    
                
                # Change current scene to original (NOT WORKING)                                          
                bpy.context.screen.scene = cur_scene
                bpy.context.screen.scene.update() 
                
                # Add newly created scene                                           
                bpy.ops.sequencer.scene_strip_add(frame_start=strip.frame_start, channel=strip.channel + 1, replace_sel=False, scene=strip.name)
                
                # Edit the strip length to match original strip                                                  
                bpy.context.sequences[0].frame_final_end = strip.frame_final_end
                
                self.report( "INFO", "DONE!" )
            return {'FINISHED'}
 
 
def register():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
def unregister():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
if __name__ == "__main__":
    register()

Things that still doesn’t work:

  1. Newly created scene-strips gets added to it’s own VSE (instead of the original scene).
  2. Input node still doesn’t link to the video.

(TMW) #14

Hi,

This seems to sort of solve the file path issue, it knows the path, but says “not found in ()” and I don’t know what that means.

import bpy
 
class CompPanel(bpy.types.Panel):
    bl_space_type = "SEQUENCE_EDITOR"
    bl_region_type = "UI"
    bl_label = "Edit strip with Compositor"
 
    def draw(self, context):
        scn = bpy.context.scene
        layout = self.layout
        row = layout.row()
        col = row.column()
 
 
        col.operator( "bpt.sample_op" )
 
 
class CompOperator(bpy.types.Operator):
 
    bl_idname = "bpt.sample_op"
    bl_label = "Edit strip with Compositor"
 
    def invoke(self, context, event ):
        
            import bpy
            # Get selected strips
            sel_strips = bpy.context.selected_sequences
            
            # Get current scene
            cur_scene = bpy.context.scene
            
            for strip in sel_strips:
                #filepath
              a = strip.filepath  
              b = bpy.path.resolve_ncase(a)
            
            # Loop selected strips                         
            for strip in sel_strips:
            
              # Check if strip is a movie
              if (strip.type == 'MOVIE'):
                # Create a new scene
                new_scene = bpy.ops.scene.new(type='EMPTY')
                
                # Name it after the moviestrip
                bpy.context.scene.name = strip.name
                
                # Change scene EndFrame to match strip             
                bpy.context.scene.frame_end = strip.frame_final_end
                
                # Setup nodes
                bpy.context.scene.use_nodes = True
                tree = bpy.context.scene.node_tree
                
                # Clear default nodes
                for n in tree.nodes:
                    tree.nodes.remove(n)
                    
                # Create input node
                rl = tree.nodes.new('IMAGE')      
                rl.location = 0,0
                print(dir(strip.filepath.find))
                # Add strip path (NOT WORKING)
                rl.layer = b
            
                # create output node
                comp = tree.nodes.new('COMPOSITE')   
                comp.location = 400,0
            
                # Link nodes
                links = tree.links
                link = links.new(rl.outputs[0],comp.inputs[0])    
                
                # Change current scene to original (NOT WORKING)                                          
                bpy.context.screen.scene = cur_scene
                bpy.context.screen.scene.update() 
                
                # Add newly created scene                                           
                bpy.ops.sequencer.scene_strip_add(frame_start=strip.frame_start, channel=strip.channel + 1, replace_sel=False, scene=strip.name)
                
                # Edit the strip length to match original strip                                                  
                bpy.context.sequences[0].frame_final_end = strip.frame_final_end
                
                self.report( "INFO", "DONE!" )
            return {'FINISHED'}
 
 
def register():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
def unregister():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
if __name__ == "__main__":
    register()

Thanks
Tom


(peddie) #15

Nice find Tom, unfortunetly I don’t know what that message means either.

Here is the latest code:

import bpy
 
class CompPanel(bpy.types.Panel):
    bl_space_type = "SEQUENCE_EDITOR"
    bl_region_type = "UI"
    bl_label = "Edit strip with Compositor"
 
    def draw(self, context):
        scn = bpy.context.scene
        layout = self.layout
        row = layout.row()
        col = row.column()
 
 
        col.operator( "bpt.sample_op" )
 
 
class CompOperator(bpy.types.Operator):
 
    bl_idname = "bpt.sample_op"
    bl_label = "Edit strip with Compositor"
 
    def invoke(self, context, event ):
        
            import bpy
            # Get selected strips
            sel_strips = bpy.context.selected_sequences
            
            # Get current scene
            cur_scene = bpy.context.scene

            # Loop selected strips                         
            for strip in sel_strips:
            
              # Check if strip is a movie
              if (strip.type == 'MOVIE'):
                # Create a new scene
                new_scene = bpy.ops.scene.new(type='EMPTY')
                
                # Name it after the moviestrip
                bpy.context.scene.name = strip.name
                
                # Change scene EndFrame to match strip             
                bpy.context.scene.frame_end = strip.frame_final_end
                
                # Setup nodes
                bpy.context.scene.use_nodes = True
                tree = bpy.context.scene.node_tree
                
                # Clear default nodes
                for n in tree.nodes:
                    tree.nodes.remove(n)
                    
                # Create input node
                rl = tree.nodes.new('IMAGE')      
                rl.location = 0,0 
                FilePath = bpy.path.resolve_ncase(strip.filepath)
                # Add strip path (NOT WORKING)
                #rl.layer = FilePath
            
                # create output node
                comp = tree.nodes.new('COMPOSITE')   
                comp.location = 400,0
            
                # Link nodes
                links = tree.links
                link = links.new(rl.outputs[0],comp.inputs[0])    
                
                # Change current scene to original (NOT WORKING)                                          
                bpy.context.screen.scene = cur_scene
                bpy.context.screen.scene.update() 
                
                # Add newly created scene                                           
                bpy.ops.sequencer.scene_strip_add(frame_start=strip.frame_start, channel=strip.channel + 1, replace_sel=False, scene=strip.name)
                
                # Edit the strip length to match original strip                                                  
                bpy.context.sequences[0].frame_final_end = strip.frame_final_end
                bpy.context.sequences[0].frame_final_start = strip.frame_final_start
                
                self.report( "INFO", "DONE!" )
            return {'FINISHED'}
 
 
def register():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
def unregister():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
if __name__ == "__main__":
    register()

Minor fixes for the strip length but the problems from earlier remains unsolved.


(TMW) #16

I also found this, replace the ‘Scene’ with whatever scene you want to change to:

bpy.context.screen.scene = bpy.data.scenes['Scene']

it works in the Python console, but not in the script editor for some reason (could be I’m missing something).

Thanks
Tom


(TMW) #17

Hi,

This sort of works, it adds the new scene without making it the active scene, so the Scene strip is added to the correct sequence editor. However all nodes have to be added by hand.

import bpy
 
class CompPanel(bpy.types.Panel):
    bl_space_type = "SEQUENCE_EDITOR"
    bl_region_type = "UI"
    bl_label = "Edit strip with Compositor"
 
    def draw(self, context):
        scn = bpy.context.scene
        layout = self.layout
        row = layout.row()
        col = row.column()
 
 
        col.operator( "bpt.sample_op" )
 
 
class CompOperator(bpy.types.Operator):
 
    bl_idname = "bpt.sample_op"
    bl_label = "Edit strip with Compositor"
 
    def invoke(self, context, event ):
        
            import bpy
            # Get selected strips
            sel_strips = bpy.context.selected_sequences
            
            # Get current scene
            cur_scene = bpy.data.scenes["Scene"]
            # Loop selected strips                         
            for strip in sel_strips:
            
              # Check if strip is a movie
              if (strip.type == 'MOVIE'):
                # Create a new scene
                #This makes the new scene, but doesn't set it as active so the Scene strip is added to the correxct scen. However you have to add the nodes yourself.
                new_scene = bpy.data.scenes.new(strip.name)
                
                # Name it after the moviestrip
                #bpy.context.scene.name = strip.name
                
                
                # Change scene EndFrame to match strip             
                #bpy.context.scene[strip.name].frame_end = strip.frame_final_end
                
                # Setup nodes
                bpy.context.scene.use_nodes = True
                tree = bpy.context.scene.node_tree
                
                # Clear default nodes
                for n in tree.nodes:
                    tree.nodes.remove(n)
                    
                # Create input node
                rl = tree.nodes.new('IMAGE')      
                rl.location = 0,0 
                FilePath = bpy.path.resolve_ncase(strip.filepath)
                # Add strip path (NOT WORKING)
                #rl.layer = FilePath
            
                # create output node
                comp = tree.nodes.new('COMPOSITE')   
                comp.location = 400,0
            
                # Link nodes
                links = tree.links
                link = links.new(rl.outputs[0],comp.inputs[0])    
                
                # Change current scene to original (NOT WORKING)                          
                
                data_context = {"blend_data": bpy.context.blend_data, "Scene": new_scene}
                bpy.context.screen.scene.update()
                print(bpy.data.screens['Video Editing'].scene) 
                
                # Add newly created scene                                           
                bpy.ops.sequencer.scene_strip_add(frame_start=strip.frame_start, channel=strip.channel + 1, replace_sel=False, scene=strip.name)
                
                
                # Edit the strip length to match original strip                                                  
                bpy.context.sequences[1].frame_final_end = strip.frame_final_end
                bpy.context.sequences[1].frame_final_start = strip.frame_final_start
                
                self.report( "INFO", "DONE!" )
            return {'FINISHED'}
 
 
def register():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
def unregister():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
if __name__ == "__main__":
    register()

Thanks
Tom


(peddie) #18

Thanks Tom!

I solved the nodes part and also figured out how to link the input node with the original file. Everything seems to be working as it should over here:

import bpy
 
class CompPanel(bpy.types.Panel):
    bl_space_type = "SEQUENCE_EDITOR"
    bl_region_type = "UI"
    bl_label = "Edit strip with Compositor"
 
    def draw(self, context):
        scn = bpy.context.scene
        layout = self.layout
        row = layout.row()
        col = row.column()
 
 
        col.operator( "bpt.sample_op" )
 
 
class CompOperator(bpy.types.Operator):
 
    bl_idname = "bpt.sample_op"
    bl_label = "Edit strip with Compositor"
 
    def invoke(self, context, event ):
        
            import bpy
            
            # Get selected strips
            sel_strips = bpy.context.selected_sequences
            
            # Get current scene
            cur_scene = bpy.data.scenes["Scene"]
            
            # Loop selected strips                         
            for strip in sel_strips:
            
              # Check if strip is a movie
              if (strip.type == 'MOVIE'):

                #Creates new scene but doesn't set it as active.
                new_scene = bpy.data.scenes.new(strip.name)
                
                # Change scene EndFrame to match strip length            
                new_scene.frame_end = strip.frame_final_duration
                
                # Setup nodes
                new_scene.use_nodes = True
                tree = new_scene.node_tree
                
                # Clear default nodes
                for n in tree.nodes:
                    tree.nodes.remove(n)
                    
                # Create input node
                rl = tree.nodes.new('IMAGE')      
                rl.location = 0,0 
                
                #Get source of strip
                StripPath = bpy.path.resolve_ncase(strip.filepath)
                StripSource = bpy.data.images.load(StripPath)
                
                # Add strip path
                rl.image = StripSource
                
                # Other settings
                rl.use_cyclic = True
                rl.use_auto_refresh = True
                rl.frame_duration = strip.frame_final_duration
                rl.frame_offset = strip.frame_offset_start

                # create output node
                comp = tree.nodes.new('COMPOSITE')   
                comp.location = 400,0
            
                # Link nodes
                links = tree.links
                link = links.new(rl.outputs[0],comp.inputs[0])    
                
                # Change current scene to original                                    
                data_context = {"blend_data": bpy.context.blend_data, "Scene": new_scene}
                bpy.context.screen.scene.update()
                
                # Add newly created scene                                           
                bpy.ops.sequencer.scene_strip_add(frame_start=strip.frame_final_start, channel=strip.channel + 1, replace_sel=False, scene=new_scene.name)                                
                # Edit the strip length to match original strip                                                  
                bpy.context.sequences[0].frame_final_end = strip.frame_final_end
                
                self.report( "INFO", "DONE!" )
            return {'FINISHED'}
 
 
def register():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
def unregister():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
if __name__ == "__main__":
    register()

Now I will test it out and see what could be improved… I’m not completely happy with how the scene-strips just lands one channel above the original, but maybe that’s the way to go!

Thanks for your hard work and support!


(TMW) #19

Thats great. one problem is there isn’t always a camera in your new scene (if you had already deleted it from your origional), this means the new scene cannot render. Also the new scene needs to have the same render settings as the origional. I’ll see what I can do.

Thanks
Tom


(peddie) #20

The camera problem seems to be a hard one… But I have added the dimensions from the original scene:

import bpy
 
class CompPanel(bpy.types.Panel):
    bl_space_type = "SEQUENCE_EDITOR"
    bl_region_type = "UI"
    bl_label = "Edit strip with Compositor"
 
    def draw(self, context):
        scn = bpy.context.scene
        layout = self.layout
        row = layout.row()
        col = row.column()
 
 
        col.operator( "bpt.sample_op" )
 
 
class CompOperator(bpy.types.Operator):
 
    bl_idname = "bpt.sample_op"
    bl_label = "Edit strip with Compositor"
 
    def invoke(self, context, event ):
        
            import bpy
            
            # Get selected strips
            sel_strips = bpy.context.selected_sequences
            
            # Get current scene
            cur_scene = bpy.context.scene
            
            # Loop selected strips                         
            for strip in sel_strips:
            
              # Check if strip is a movie
              if (strip.type == 'MOVIE'):

                # Creates new scene but doesn't set it as active.
                new_scene = bpy.data.scenes.new(strip.name)
                
                # Change render settings for new scene to match original scene
                new_scene.render.resolution_x = cur_scene.render.resolution_x
                new_scene.render.resolution_y = cur_scene.render.resolution_y
                new_scene.render.resolution_percentage = cur_scene.render.resolution_percentage
                new_scene.render.fps  = cur_scene.render.fps 
                
                # Add camera to new scene
                  
               

                # Change new scene EndFrame to match strip length            
                new_scene.frame_end = strip.frame_final_duration
                
                # Setup nodes
                new_scene.use_nodes = True
                tree = new_scene.node_tree
                
                # Clear default nodes
                for n in tree.nodes:
                    tree.nodes.remove(n)
                    
                # Create input node
                rl = tree.nodes.new('IMAGE')      
                rl.location = 0,0 
                
                #Get source of strip
                StripPath = bpy.path.resolve_ncase(strip.filepath)
                StripSource = bpy.data.images.load(StripPath)
                
                # Add strip path
                rl.image = StripSource
                
                # Other settings
                rl.use_cyclic = True
                rl.use_auto_refresh = True
                rl.frame_duration = strip.frame_final_duration
                rl.frame_offset = strip.frame_offset_start

                # create output node
                comp = tree.nodes.new('COMPOSITE')   
                comp.location = 400,0
            
                # Link nodes
                links = tree.links
                link = links.new(rl.outputs[0],comp.inputs[0])    
                
                # Change current scene to original                                    
                data_context = {"blend_data": bpy.context.blend_data, "Scene": new_scene}
                bpy.context.screen.scene.update()
                
                # Add newly created scene                                           
                bpy.ops.sequencer.scene_strip_add(frame_start=strip.frame_final_start, channel=strip.channel + 1, replace_sel=False, scene=new_scene.name)                                
                # Edit the strip length to match original strip                                                  
                bpy.context.sequences[0].frame_final_end = strip.frame_final_end
                
                self.report( "INFO", "DONE!" )
            return {'FINISHED'}
 
 
def register():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
def unregister():
    bpy.utils.register_class( CompPanel )
    bpy.utils.register_class( CompOperator )
 
 
if __name__ == "__main__":
    register()

It would be better to link the new scenes to the strip-dimension but I can’t find out how… Do you have any thoughts on the camera?