-
Notifications
You must be signed in to change notification settings - Fork 20
/
switch_to_scene.py
75 lines (60 loc) · 2.58 KB
/
switch_to_scene.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import bpy
from .. import fountain
from pathlib import Path
class SCREENWRITER_OT_switch_to_scene(bpy.types.Operator):
"""Switch to Screenplay Scene"""
bl_idname = "text.switch_to_scene"
bl_label = "Switch to Scene"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
space = bpy.context.space_data
try:
filepath = space.text.name
if filepath.strip() == "": return False
return ((space.type == 'TEXT_EDITOR')
and Path(filepath).suffix == ".fountain")
except AttributeError: return False
def execute(self, context):
bpy.ops.scene.preview_fountain() # update title_page_index
fountain_script = bpy.context.area.spaces.active.text.as_string()
if fountain_script.strip() == "": return {"CANCELLED"}
F = fountain.Fountain(fountain_script)
current_text = bpy.context.space_data.text.name
if current_text.strip() == "": return
current_scene = bpy.context.window.scene
scene_name = ""
scene_name_found = ""
for fc, f in enumerate(F.elements):
if f.element_type == 'Scene Heading':
scene_name = f.element_text.title()
if bpy.context.scene.title_page_index == f.original_line:
scene_name_found = scene_name
for s in bpy.data.scenes:
if scene_name == s.name:
bpy.context.window.scene = bpy.data.scenes[scene_name]
break
break
if current_scene.name == bpy.context.window.scene.name and scene_name_found:
msg = "Scene not found: " + scene_name_found
self.report({'INFO'}, msg)
return {'FINISHED'}
class SCREENWRITER_OT_switch_to_master(bpy.types.Operator):
"""Switch to Master Sequence Scene"""
bl_idname = "text.switch_to_master"
bl_label = "Switch to Master"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
space = bpy.context.space_data
try:
filepath = space.text.name
if filepath.strip() == "": return False
return ((space.type == 'TEXT_EDITOR')
and Path(filepath).suffix == ".fountain")
except AttributeError: return False
def execute(self, context):
scene = bpy.context.scene
if scene.master_sequence != "":
bpy.context.window.scene = bpy.data.scenes[scene.master_sequence]
return {'FINISHED'}