/
__init__.py
executable file
·98 lines (74 loc) · 3.11 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
bl_info = {
"name": "JSON Mesh Export",
"author": "Nathan Faucett",
"blender": (2,80,0),
"version": (0,0,2),
"location": "File > Import-Export",
"description": "Import-Export JSON data format (only export avalable now)",
"category": "Import-Export",
"wiki_url": "https://github.com/warmwaffles/io_mesh_json",
"tracker_url": "https://github.com/warmwaffles/io_mesh_json",
}
import bpy
from bpy.props import *
from bpy_extras.io_utils import ExportHelper, ImportHelper
# ################################################################
# Import JSON
# ################################################################
class ImportJSON( bpy.types.Operator, ImportHelper ):
bl_idname = "import.json"
bl_label = "Import JSON"
filename_ext = ".json"
filter_glob = StringProperty( default="*.json", options={"HIDDEN"})
def execute( self, context ):
import io_mesh_json.import_json
return io_mesh_json.import_json.load( self, context, **self.properties )
# ################################################################
# Export JSON
# ################################################################
class ExportJSON( bpy.types.Operator, ExportHelper ):
bl_idname = "export.json"
bl_label = "Export JSON"
filename_ext = ".json"
def invoke( self, context, event ):
return ExportHelper.invoke( self, context, event )
@classmethod
def poll( cls, context ):
return context.active_object != None
def execute( self, context ):
print("Selected: " + context.active_object.name )
if not self.properties.filepath:
raise Exception("filename not set")
filepath = self.filepath
import io_mesh_json.export_json
return io_mesh_json.export_json.save( self, context, **self.properties )
# ################################################################
# Common
# ################################################################
__classes__ = (
ImportJSON,
ExportJSON,
)
def menu_func_export( self, context ):
default_path = bpy.data.filepath.replace(".blend", ".json")
self.layout.operator( ExportJSON.bl_idname, text="JSON (.json)").filepath = default_path
def menu_func_import( self, context ):
self.layout.operator( ImportJSON.bl_idname, text="JSON (.json)")
def register():
# bpy.utils.register_module(__name__)
for c in __classes__:
bpy.utils.register_class(c);
# bpy.types.INFO_MT_file_export.append(menu_func_export)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
# bpy.types.INFO_MT_file_import.append(menu_func_import)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
def unregister():
# bpy.utils.unregister_module(__name__)
for c in reversed(__classes__):
bpy.utils.unregister_class(c);
# bpy.types.INFO_MT_file_export.remove(menu_func_export)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
# bpy.types.INFO_MT_file_import.remove(menu_func_import)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
if __name__ == "__main__":
register()