Import_3ds: Improved distance cue node setup
[blender-addons.git] / power_sequencer / operators / scene_merge_from.py
blob843d30313adddb7464d7bf78b20c25c476c77043
1 # SPDX-FileCopyrightText: 2016-2020 by Nathan Lovato, Daniel Oakey, Razvan Radulescu, and contributors
3 # SPDX-License-Identifier: GPL-3.0-or-later
5 import bpy
7 from .utils.doc import doc_name, doc_idname, doc_brief, doc_description
10 class POWER_SEQUENCER_OT_merge_from_scene_strip(bpy.types.Operator):
11 """
12 *brief* Copies all sequences and markers from a SceneStrip's scene into
13 the active scene. Optionally delete the source scene and the strip
15 WARNING: Currently the operator doesn't recreate any animation data,
16 be careful by choosing to delete the scene after the merge
17 """
19 doc = {
20 "name": doc_name(__qualname__),
21 "demo": "",
22 "description": doc_description(__doc__),
23 "shortcuts": [],
24 "keymap": "Sequencer",
26 bl_idname = doc_idname(__qualname__)
27 bl_label = doc["name"]
28 bl_description = doc_brief(doc["description"])
29 bl_options = {"REGISTER", "UNDO"}
31 delete_scene: bpy.props.BoolProperty(
32 name="Delete Strip's scene",
33 description="Delete the SceneStrip's scene after the merging",
34 default=True,
37 @classmethod
38 def poll(cls, context):
39 return context.scene.sequence_editor.active_strip
41 def invoke(self, context, event):
42 window_manager = context.window_manager
43 return window_manager.invoke_props_dialog(self)
45 def execute(self, context):
46 strip = context.scene.sequence_editor.active_strip
47 if strip.type != "SCENE":
48 return {"FINISHED"}
49 strip_scene = strip.scene
50 start_scene = context.window.scene
52 self.merge_markers(context, strip_scene, start_scene)
53 self.merge_strips(context, strip_scene, start_scene)
55 if not self.delete_scene:
56 return {"FINISHED"}
58 bpy.ops.sequencer.select_all(action="DESELECT")
59 strip.select = True
60 bpy.ops.sequencer.delete()
61 context.window.scene = strip_scene
62 bpy.ops.scene.delete()
63 context.window.scene = start_scene
64 self.report(type={"WARNING"}, message="Merged scenes lose all their animation data.")
66 return {"FINISHED"}
68 def merge_strips(self, context, source_scene, target_scene):
69 context.window.scene = source_scene
70 current_frame = context.scene.frame_current
71 context.scene.frame_current = context.scene.frame_start
72 bpy.ops.sequencer.select_all(action="SELECT")
73 bpy.ops.sequencer.copy()
74 context.scene.frame_current = current_frame
76 context.window.scene = target_scene
77 current_frame = context.scene.frame_current
78 active = context.scene.sequence_editor.active_strip
79 context.scene.frame_current = active.frame_start
80 bpy.ops.sequencer.select_all(action="DESELECT")
81 bpy.ops.sequencer.paste()
83 context.scene.frame_current = current_frame
85 def merge_markers(self, context, source_scene, target_scene):
86 if len(source_scene.timeline_markers) == 0:
87 return
89 if len(target_scene.timeline_markers) > 0:
90 bpy.ops.marker.select_all(action="DESELECT")
92 bpy.context.window.scene = source_scene
93 bpy.ops.marker.select_all(action="SELECT")
94 bpy.ops.marker.make_links_scene(scene=target_scene.name)
96 bpy.context.window.scene = target_scene
97 active = bpy.context.window.scene.sequence_editor.active_strip
99 # Offset to account for source scenes starting on any frame.
100 time_offset = active.frame_start - source_scene.frame_start
101 bpy.ops.marker.move(frames=time_offset)
102 bpy.ops.marker.select_all(action="DESELECT")