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
|
import bpy, math
from . import blender_funcs
# just a simple OBJ exporter wrapper
# it only selects all the meshes inside an armature and sets some OBJ exporter variables
# write_kcl_obj function
# function to write custom obj file for kcl conversion
def write_kcl_obj(context, filepath):
# this thing is always needed for stuff
scene = bpy.context.scene
# if nothing is selected end the exporter
if (scene.objects.active == None or scene.objects.active.type != 'ARMATURE'):
if (scene.objects.active == None):
blender_funcs.disp_msg("No Armature selected. Select one and try again.")
else:
blender_funcs.disp_msg("No Armature selected. Currently selecting: \"%s\""
% (scene.objects.active.name))
return {'FINISHED'}
# get armature object
armature = scene.objects.active
print("\nArmature found: \"%s\"" % (armature.name))
# change to object mode
bpy.ops.object.mode_set(mode='OBJECT')
# check if the armature contains only mesh objects inside
for obj in armature.children:
if (obj.type != 'MESH'):
blender_funcs.disp_msg("\"%s\": contains non-mesh object (%s)."
% (armature.name, obj.name))
return {'FINISHED'}
# select all the meshes inside the armature
blender_funcs.select_obj(scene, armature, True)
# export the object
bpy.ops.export_scene.obj(filepath = filepath, axis_up = "Y", axis_forward = "-Z",
use_selection = True, use_triangles = True, global_scale = 100,
use_materials = True, use_normals = True)
# done!
blender_funcs.select_obj(scene, armature, False)
blender_funcs.disp_msg("Meshes from \"%s\" exported!" % (armature.name))
return {'FINISHED'}
# Stuff down is for the menu appending
# of the exporter to work plus some setting stuff
# comes from a Blender importer template
from bpy_extras.io_utils import ExportHelper
from bpy.props import StringProperty, BoolProperty, EnumProperty
from bpy.types import Operator
class export_obj_kcl(Operator, ExportHelper):
"""Export a OBJ file for KCL conversion"""
bl_idname = "export_scene.obj_kcl"
bl_label = "Export OBJ for KCL (.OBJ)"
filename_ext = ".obj"
filter_glob = StringProperty(default = "*.obj", options = {'HIDDEN'}, maxlen = 255)
def execute(self, context):
return write_kcl_obj(context, self.filepath)
# Only needed if you want to add into a dynamic menu
def menu_export_obj_kcl(self, context):
self.layout.operator(export_obj_kcl.bl_idname, text="OBJ for KCL (.obj)")
bpy.utils.register_class(export_obj_kcl)
bpy.types.INFO_MT_file_export.append(menu_export_obj_kcl)
# test call
bpy.ops.export_scene.obj_kcl('INVOKE_DEFAULT')
|