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")
23 # ------------------------------
25 # ------------------------------
27 def poll(cls
, context
):
29 scene_base
= scene
.storypencil_base_scene
30 if scene_base
is not None and scene_base
.name
in bpy
.data
.scenes
:
35 def invoke(self
, context
, event
):
36 return context
.window_manager
.invoke_props_dialog(self
)
38 def draw(self
, context
):
41 col
.prop(self
, "scene_name", text
="Scene Name")
43 def format_to3(self
, value
):
46 # ------------------------------
47 # Execute button action
48 # ------------------------------
49 def execute(self
, context
):
50 scene_prv
= context
.scene
51 cfra_prv
= scene_prv
.frame_current
52 scene_base
= scene_prv
.storypencil_base_scene
54 # Set context to base scene and duplicate
55 context
.window
.scene
= scene_base
56 bpy
.ops
.scene
.new(type='FULL_COPY')
57 scene_new
= context
.window
.scene
58 new_name
= scene_prv
.storypencil_name_prefix
+ \
59 self
.scene_name
+ scene_prv
.storypencil_name_suffix
61 while new_name
in bpy
.data
.scenes
:
63 new_name
= scene_prv
.storypencil_name_prefix
+ self
.scene_name
+ \
64 scene_prv
.storypencil_name_suffix
+ '.' + self
.format_to3(id)
66 scene_new
.name
= new_name
67 # Set duration of new scene
68 scene_new
.frame_end
= scene_new
.frame_start
+ \
69 scene_prv
.storypencil_scene_duration
- 1
71 # Back to original scene
72 context
.window
.scene
= scene_prv
73 scene_prv
.frame_current
= cfra_prv
74 bpy
.ops
.sequencer
.scene_strip_add(
75 frame_start
=cfra_prv
, scene
=scene_new
.name
)
77 scene_new
.update_tag()
78 scene_prv
.update_tag()
83 def draw_new_scene(self
, context
):
84 """Add menu options."""
86 self
.layout
.operator_context
= 'INVOKE_REGION_WIN'
87 row
= self
.layout
.row(align
=True)
88 row
.operator(STORYPENCIL_OT_NewScene
.bl_idname
, text
="New Template Scene")
91 def setup_storyboard(self
, context
):
92 """Add Setup menu option."""
93 # For security, check if this is the default template.
94 is_gpencil
= context
.active_object
and context
.active_object
.name
== 'Stroke'
95 if is_gpencil
and context
.workspace
.name
in ('2D Animation', '2D Full Canvas') and context
.scene
.name
== 'Scene':
96 if "Video Editing" not in bpy
.data
.workspaces
:
97 row
= self
.layout
.row(align
=True)
99 row
= self
.layout
.row(align
=True)
100 row
.operator(STORYPENCIL_OT_Setup
.bl_idname
,
101 text
="Setup Storyboard Session")
104 # -------------------------------------------------------------
105 # Setup all environment
107 # -------------------------------------------------------------
108 class STORYPENCIL_OT_Setup(Operator
):
109 bl_idname
= "storypencil.setup"
111 bl_description
= "Configure all settings for a storyboard session"
112 bl_options
= {'REGISTER', 'UNDO'}
114 # ------------------------------
116 # ------------------------------
118 def poll(cls
, context
):
121 def get_workspace(self
, type):
122 for wrk
in bpy
.data
.workspaces
:
128 # ------------------------------
129 # Execute button action
130 # ------------------------------
131 def execute(self
, context
):
132 scene_base
= context
.scene
135 if "Video Editing" not in bpy
.data
.workspaces
:
137 for path
in bpy
.utils
.app_template_paths():
140 filepath
= os
.path
.join(
141 template_path
, "Video_Editing", "startup.blend")
142 bpy
.ops
.workspace
.append_activate(
143 idname
="Video Editing", filepath
=filepath
)
146 scene_edit
= context
.scene
147 scene_edit
.name
= 'Edit'
148 # Rename original base scene
149 scene_base
.name
= 'Base'
150 # Setup Edit scene settings
151 scene_edit
.storypencil_main_workspace
= self
.get_workspace(
153 scene_edit
.storypencil_main_scene
= scene_edit
154 scene_edit
.storypencil_base_scene
= scene_base
155 scene_edit
.storypencil_edit_workspace
= self
.get_workspace(
158 # Add a new strip (need set the area context)
159 context
.window
.scene
= scene_edit
160 area_prv
= context
.area
.ui_type
161 context
.area
.ui_type
= 'SEQUENCE_EDITOR'
162 prv_frame
= scene_edit
.frame_current
164 scene_edit
.frame_current
= scene_edit
.frame_start
165 bpy
.ops
.storypencil
.new_scene()
167 context
.area
.ui_type
= area_prv
168 scene_edit
.frame_current
= prv_frame
170 scene_edit
.update_tag()
171 bpy
.ops
.sequencer
.reload()