-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
115 lines (93 loc) · 3.44 KB
/
main.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
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
import zipfile
import os
import shutil
from bpy_extras.io_utils import (
ImportHelper,
ExportHelper
)
from bpy.props import (
StringProperty
)
class ImportMVR(bpy.types.Operator, ImportHelper):
"""Import from 3DS file format (.3ds)"""
bl_idname = "import_scene.mvr"
bl_label = 'Import MVR'
bl_options = {'UNDO'}
filename_ext = ".mvr"
filter_glob: StringProperty(default="*.mvr", options={'HIDDEN'})
def execute(self, context):
keywords = self.as_keywords()
mvr_path = keywords['filepath']
mvr_file = zipfile.ZipFile(mvr_path, 'r')
print(mvr_file.read("demo.txt").decode("UTF-8"))
return {'FINISHED'}
class ExportMVR(bpy.types.Operator, ExportHelper):
"""Export to 3DS file format (.3ds)"""
bl_idname = "export_scene.mvr"
bl_label = 'Export MVR'
filename_ext = ".mvr"
filter_glob: StringProperty(
default="*.mvr",
options={'HIDDEN'},
)
def execute(self, context):
keywords = self.as_keywords()
mvr_path = keywords["filepath"]
root_path = f'{os.path.dirname(keywords["filepath"])}/temp_mvr'
os.makedirs(root_path)
file = open(f'{root_path}/demo.txt', "w")
try:
file.write("Leben is noch toller :)")
file.close()
print("File saved")
# create zip file
try:
zip_file = zipfile.ZipFile(keywords["filepath"], "w")
zip_file.write(f'{root_path}/demo.txt', 'demo.txt')
zip_file.close()
print("ZIP File saved")
except:
zip_file.close()
print("Could not create zip file")
except:
print("File not saved")
shutil.rmtree(root_path)
return {'FINISHED'}
# Add to a menu
def menu_func_export(self, context):
self.layout.operator(ExportMVR.bl_idname, text="My virtual Rig (.mvr)")
def menu_func_import(self, context):
self.layout.operator(ImportMVR.bl_idname, text="My virtual Rig (.mvr)")
def register():
bpy.utils.register_class(ImportMVR)
bpy.utils.register_class(ExportMVR)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_class(ImportMVR)
bpy.utils.unregister_class(ExportMVR)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
# This allows you to run the script directly from Blender's Text editor
# to test the add-on without having to install it.
if __name__ == "__main__":
print("Registering.")
register()