You can do the trick with if len(bpy.context.selected_sequences) > 0: bpy.ops.sequencer.snap(frame = bpy.context.scene.frame_current - bpy.context.selected_sequences[0].frame_final_duration)
.
Unfortunately you cannot write something specific like an expression into the Frame field fo the RNA SEQUENCER_OT_snap
when you use sequencer.snap
as the operator identifier for a new key map item in your Input Configuration.
But here's a workaround based on another answer here with the advantage that you can use any scripts saved in text data blocks via a hotkey:
Workaround [use this line of code via a Sequencer Hotkey]
Preparations
Save the following Script as a *.py
file onto your Computer:
import bpy
bl_info = {
# modified version of zeffiis quick script runner, see https://gist.github.com/zeffii/2b488961226ee1ecefcf
"name": "Sequencer Script Runner",
"author": "Samoth",
"version": (0, 1, 0),
"blender": (2, 7, 6),
"location": "Sequencer, Properties Panel (right)",
"category": "Sequencer"
}
class GlobalScriptRunner(bpy.types.Operator):
bl_idname = "sequencer.script_runner"
bl_label = "Sequencer Script Runner"
def execute(self, context):
# or put own script here...
textblock_name = context.scene.global_script_to_run
textblock = bpy.data.texts.get(textblock_name)
if textblock:
textblock_as_string = textblock.as_string()
exec(textblock_as_string)
return {'FINISHED'}
else:
return {'CANCELLED'}
class ScriptRunnerPanel(bpy.types.Panel):
"""Creates a Panel in the Sequencer Properties Panel"""
bl_label = "Script Runner"
bl_idname = "SCENE_PT_script_runner"
bl_space_type = 'SEQUENCE_EDITOR'
bl_region_type = 'UI'
def draw(self, context):
layout = self.layout
layout.label('Script to run from Shortcut')
layout.prop_search(context.scene, "global_script_to_run", bpy.data, "texts")
def register():
bpy.types.Scene.global_script_to_run = bpy.props.StringProperty()
bpy.utils.register_class(GlobalScriptRunner)
bpy.utils.register_class(ScriptRunnerPanel)
def unregister():
bpy.utils.unregister_class(GlobalScriptRunner)
bpy.utils.unregister_class(ScriptRunnerPanel)
del bpy.types.Scene.global_script_to_run
Select it via Install from File... in the Blender User Preferences' (Ctrl Alt U) Add-ons tab and enable it.
Save the above Code line that does the trick into a new Text data block in a Text Editor view.
Usage
- Assign a new Hotkey for the Add-on:
- Select Sequencer and then Sequencer (Global) in the Input tab in Blenders User Preferences.
- Scroll way down and Add New
- Put
sequencer.script_runner
into the Operator Identifier Field
(You can see that it worked when the Key map events title will change to "Sequencer Script Runner" and the RNA changes to SEQUENCER_OT_script_runner
)
- Assign a Hotkey Combination, probably use Keyboard and Shift Alt S
- Open a Properties Panel in the Video Sequence Editor
- Select the above created Text data block via its name in the Script Runner panel
- Just use the newly assigned Hotkey with some selected Strips (I tested it with a Color Strip) and enjoy ;-)
Explanation
You could put your Script lines directly into the Add-ons code into the def execute(self, context):
block (where I placed the comment # or put own script here...
) and omit the whole Panel creation stuff below. But this will reduce your abilities to this single usage example.
This way with the selectable Text data block you can save multiple ones, name them accordingly and run any selected one of them via the same Hotkey. And this has the huge advantage, that you can do context related stuff in there. You will notice that the above Script line won't work when you simply put it into a Text data block and hit Run Script (which already has a Hotkey assigned). That's due to your cursor not being above the VSE when you hit Run Script and therefore Blenders context is wrong for this to work properly. This isn't the case when you selected a Strip and then call the Script via this Add-on via the newly assigned Hotkey. Then you'd still be hovering over the VSE, so the context for the Script line is fine and it does what you asked for.