forked from Loyalists/Sollumz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ycdexport.py
60 lines (41 loc) · 1.74 KB
/
ycdexport.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
import xml.etree.ElementTree as ET
import bpy
from bpy_extras.io_utils import ExportHelper
from bpy.types import Operator
from .formats.ycd.ClipDictionary import ClipDictionary
from .ydrexport import prettify
def findClipDictionary(context):
objects = context.scene.objects
for obj in objects:
if obj.sollumtype == 'Clip Dictionary':
return obj
return None
def write_ycd_xml(context, filepath):
clipDictObj = findClipDictionary(context)
if clipDictObj is None:
return "Clip Dictionary not found!"
clipDict = ClipDictionary.fromObject(clipDictObj)
clipDictNode = clipDict.toXml()
print("*** Complete ***")
xmlstr = prettify(clipDictNode)
with open(filepath, "w") as f:
f.write(xmlstr)
return "Sollumz Clip Dictionary was succesfully exported to " + filepath
class ExportYcdXml(Operator, ExportHelper):
"""This appears in the tooltip of the operator and in the generated docs"""
bl_idname = "exportxml.ycd" # important since its how bpy.ops.import_test.some_data is constructed
bl_label = "Export Ycd"
# ImportHelper mixin class uses this
filename_ext = ".ycd.xml"
def execute(self, context):
write_ycd_xml(context, self.filepath) # pylint: disable=no-member
return {'FINISHED'}
# Only needed if you want to add into a dynamic menu
def menu_func_export_ycd(self, context): # pylint: disable=unused-argument
self.layout.operator(ExportYcdXml.bl_idname, text="Ycd Xml Export (.ycd.xml)")
def register():
bpy.utils.register_class(ExportYcdXml)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export_ycd)
def unregister():
bpy.utils.unregister_class(ExportYcdXml)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export_ycd)