1 # SPDX-License-Identifier: GPL-2.0-or-later
6 from bpy
.types
import (
11 # -------------------------------------------------------------
12 # Add a new scene and set to new strip
14 # -------------------------------------------------------------
15 class STORYPENCIL_OT_NewScene(Operator
):
16 bl_idname
= "storypencil.new_scene"
17 bl_label
= "New Scene"
18 bl_description
= "Create a new scene base on template scene"
19 bl_options
= {'REGISTER', 'UNDO'}
21 scene_name
: bpy
.props
.StringProperty(default
="Scene")
22 num_strips
: bpy
.props
.IntProperty(default
=1, min=1, max=128, description
="Number of scenes to add")
24 # ------------------------------
26 # ------------------------------
28 def poll(cls
, context
):
30 scene_base
= scene
.storypencil_base_scene
31 if scene_base
is not None and scene_base
.name
in bpy
.data
.scenes
:
36 def invoke(self
, context
, event
):
37 return context
.window_manager
.invoke_props_dialog(self
)
39 def draw(self
, context
):
42 col
.prop(self
, "scene_name", text
="Scene Name")
43 col
.prop(self
, "num_strips", text
="Repeat")
45 def format_to3(self
, value
):
48 # ------------------------------
49 # Execute button action
50 # ------------------------------
51 def execute(self
, context
):
52 scene_prv
= context
.scene
53 cfra_prv
= scene_prv
.frame_current
54 scene_base
= scene_prv
.storypencil_base_scene
55 repeat
= self
.num_strips
58 for i
in range(repeat
):
59 # Set context to base scene and duplicate
60 context
.window
.scene
= scene_base
61 bpy
.ops
.scene
.new(type='FULL_COPY')
62 scene_new
= context
.window
.scene
63 new_name
= scene_prv
.storypencil_name_prefix
+ \
64 self
.scene_name
+ scene_prv
.storypencil_name_suffix
66 while new_name
in bpy
.data
.scenes
:
68 new_name
= scene_prv
.storypencil_name_prefix
+ self
.scene_name
+ \
69 scene_prv
.storypencil_name_suffix
+ '.' + self
.format_to3(id)
71 scene_new
.name
= new_name
72 # Set duration of new scene
73 scene_new
.frame_end
= scene_new
.frame_start
+ \
74 scene_prv
.storypencil_scene_duration
- 1
76 # Back to original scene
77 context
.window
.scene
= scene_prv
78 scene_prv
.frame_current
= cfra_prv
79 bpy
.ops
.sequencer
.scene_strip_add(
80 frame_start
=cfra_prv
+ offset
, scene
=scene_new
.name
)
82 # Add offset for repeat
83 offset
+= scene_new
.frame_end
- scene_new
.frame_start
+ 1
85 scene_new
.update_tag()
86 scene_prv
.update_tag()
91 def draw_new_scene(self
, context
):
92 """Add menu options."""
94 self
.layout
.operator_context
= 'INVOKE_REGION_WIN'
95 row
= self
.layout
.row(align
=True)
96 row
.operator(STORYPENCIL_OT_NewScene
.bl_idname
, text
="New Template Scene")
99 def setup_storyboard(self
, context
):
100 """Add Setup menu option."""
101 # For security, check if this is the default template.
102 is_gpencil
= context
.active_object
and context
.active_object
.name
== 'Stroke'
103 if is_gpencil
and context
.workspace
.name
in ('2D Animation', '2D Full Canvas') and context
.scene
.name
== 'Scene':
104 if "Video Editing" not in bpy
.data
.workspaces
:
105 row
= self
.layout
.row(align
=True)
107 row
= self
.layout
.row(align
=True)
108 row
.operator(STORYPENCIL_OT_Setup
.bl_idname
,
109 text
="Setup Storyboard Session")
112 # -------------------------------------------------------------
113 # Setup all environment
115 # -------------------------------------------------------------
116 class STORYPENCIL_OT_Setup(Operator
):
117 bl_idname
= "storypencil.setup"
119 bl_description
= "Configure all settings for a storyboard session"
120 bl_options
= {'REGISTER', 'UNDO'}
122 # ------------------------------
124 # ------------------------------
126 def poll(cls
, context
):
129 def get_workspace(self
, type):
130 for wrk
in bpy
.data
.workspaces
:
136 # ------------------------------
137 # Execute button action
138 # ------------------------------
139 def execute(self
, context
):
140 scene_base
= context
.scene
143 if "Video Editing" not in bpy
.data
.workspaces
:
145 for path
in bpy
.utils
.app_template_paths():
148 filepath
= os
.path
.join(
149 template_path
, "Video_Editing", "startup.blend")
150 bpy
.ops
.workspace
.append_activate(
151 idname
="Video Editing", filepath
=filepath
)
154 scene_edit
= context
.scene
155 scene_edit
.name
= 'Edit'
156 # Rename original base scene
157 scene_base
.name
= 'Base'
158 # Setup Edit scene settings
159 scene_edit
.storypencil_main_workspace
= self
.get_workspace(
161 scene_edit
.storypencil_main_scene
= scene_edit
162 scene_edit
.storypencil_base_scene
= scene_base
163 scene_edit
.storypencil_edit_workspace
= self
.get_workspace(
166 # Add a new strip (need set the area context)
167 context
.window
.scene
= scene_edit
168 area_prv
= context
.area
.ui_type
169 context
.area
.ui_type
= 'SEQUENCE_EDITOR'
170 prv_frame
= scene_edit
.frame_current
172 scene_edit
.frame_current
= scene_edit
.frame_start
173 bpy
.ops
.storypencil
.new_scene()
175 context
.area
.ui_type
= area_prv
176 scene_edit
.frame_current
= prv_frame
178 scene_edit
.update_tag()
179 bpy
.ops
.sequencer
.reload()