-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
120 lines (90 loc) · 3.52 KB
/
__init__.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import bpy, os
from bpy.props import StringProperty
from bpy.types import Operator, Panel
from bpy.utils import register_class, unregister_class
from .utils import load_presets, error_dialog, set_default_preset
from .preferences import BLENDERPROJECTMANAGER_PT_presets, classes as preferences_classes
from .presets import classes as presets_classes
bl_info = {
"name" : "Project Manager",
"author" : "Christopher Hosken",
"version" : (1, 0, 0),
"blender" : (4, 2, 0),
"description" : "",
"warning" : "",
"support": "COMMUNITY",
"doc_url": "",
"tracker_url": "",
"category" : "System"
}
class BLENDERPROJECTMANAGER_OT_Add(Operator):
bl_label = "New Project"
bl_idname = "wm.project_add"
bl_description = "Create a Blender project folder"
filepath : StringProperty()
filename : StringProperty()
filter_glob: StringProperty(
default="",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
def execute(self, context):
# Create the root folder with the project name
try:
os.mkdir(self.filepath)
except FileExistsError:
error_dialog("That project already exists!", "FileExistsError")
return {"CANCELLED"}
# Create the subdirs
for subdir in context.scene.bpm.subdirs:
os.mkdir(os.path.join(self.filepath, subdir.name))
# Create and open the new blender file
if (context.scene.bpm.prefs.auto_gen_file):
bpy.ops.wm.save_as_mainfile(filepath=os.path.join(self.filepath, self.filename.lower() + ".blend"))
return {"FINISHED"}
def invoke(self, context, event):
# Open the file browser and have the user create their folder name.
self.filepath = os.path.join(context.blend_data.filepath, "NewProject")
context.window_manager.fileselect_add(self)
return {"RUNNING_MODAL"}
def draw(self, context):
pass
class BLENDERPROJECTMANAGER_PT_browser(Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "Project Settings"
@classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator is not None and operator.bl_idname == 'WM_OT_project_add'
def draw(self, context):
layout = self.layout
prefs = context.scene.bpm.prefs
subdirs = context.scene.bpm.subdirs
row = layout.row()
row.prop(prefs, 'auto_gen_file', text="Create .blend")
box = layout.box()
row = box.row()
row.label(text="Custom Subdirectories")
row.operator("preferences.add_bpm_subdir", text="", icon="ADD", emboss=False)
BLENDERPROJECTMANAGER_PT_presets.draw_panel_header(row)
for i, subdir in enumerate(subdirs):
row = box.row()
row.prop(subdir, "name")
row.operator("preferences.remove_bpm_subdir", text="", icon='X', emboss=False).index = i
classes = [BLENDERPROJECTMANAGER_OT_Add, BLENDERPROJECTMANAGER_PT_browser] + presets_classes + preferences_classes
def draw(self, context):
layout = self.layout
layout.operator("wm.project_add", text="New Project", icon='FILE_FOLDER')
def register():
load_presets()
for cls in classes:
register_class(cls)
bpy.types.TOPBAR_MT_file.prepend(draw)
def unregister():
for cls in classes:
unregister_class(cls)
bpy.types.TOPBAR_MT_file.remove(draw)
if __name__ == "__main__":
register()