Blender batch exporter

Working a lot with Unity and Unreal Engine, I experienced issues in the workflow with Blender and the Engines. Exporting multiple objects can be tedious and result in errors like wrong pivot points.
In order to improve and speed up the workflow I wrote a python script which exports multiple objects to individual files. The script generates a panel with options such as export format and export directory. The user simply selects several objects and clicks export!


Features:
-Easy to use menu with export options
-Export with correct pivot without changing position of object
-OBJ and FBX support
-option to triangulate objects
-option to add light map UV channel and automatic unwrap

You can download and use the script yourself. Further down you can find the source code for the .py file.


Challenges:
This was the first time I got in touch with Python and the Blender API. I had to read up on the general structure of a script, creating a menu and the commands used in Blender.


import bpy
import os
import sys
from mathutils import Vector

bpy.types.Scene.Triangulate = bpy.props.BoolProperty(
        name = "Triangulate", 
        description = "True or False?")
        
bpy.types.Scene.LightMap = bpy.props.BoolProperty(
        name = "Add LightMap", 
        description = "Adds UV channel with unwrap if no Lightmap chanell was found")
        
bpy.types.Scene.ScaleSetting = bpy.props.FloatProperty(
        name = "Scale", 
        default = 1.00,
        min = 0,
        max = 1000,
        description = "Set Scale")
        
bpy.types.Scene.Format = bpy.props.EnumProperty(
        items = [('0', '.obj', 'Export to OBJ'),
                 ('1', '.fbx', 'Export to FBX')],
        name = "Format")
        
bpy.types.Scene.WriteMaterials = bpy.props.BoolProperty(
        name = "Write Materials", 
        description = "True or False?")
        
bpy.types.Scene.Up = bpy.props.EnumProperty(
        items = [('0', 'X', 'Up X'),
                 ('1', 'Y', 'Up Y'),
                 ('2', 'Z', 'Up Z')],
        name = "Up Vector")
        
bpy.types.Scene.Root_folder = bpy.props.StringProperty(
        name="Export Directory",
        description="Files will be exported to this directory",
        subtype="DIR_PATH")    
              
class BatchExporter(bpy.types.Operator) :
    bl_idname = "mesh.export_models"
    bl_label = "Export objects"
    bl_options = {"UNDO"}

    def invoke(self, context, event) :          
        #Get export path    
        folder = context.scene.Root_folder
        filepath_full = bpy.path.abspath(folder)
        
        #Get all selected objects
        selection_names = bpy.context.selected_objects
        
        #unselect all objects     
        bpy.ops.object.select_all(action='DESELECT')
                
        #loop over object list, export one by one
        for obj in selection_names:
            obj.select = True;
        
            scene.objects.active = obj
            
            posOld = obj.location[:]
            
            #set object to center
            obj.location = Vector([0,0,0])
            #apply rotation and scale
            bpy.ops.object.transform_apply(location = False, scale = True, rotation = True)
            mesh = obj.data
            
            if context.scene.LightMap:
                #get UV channels, add channel if there is only one channel
                uv_textures = mesh.uv_textures
                lenght = len(uv_textures)
                if lenght < 2:
                    for channel in uv_textures:
                        if not channel.name in 'LightMap':
                            uv_textures.new('LightMap')
            
                #unwrap with smart uv_project
                bpy.ops.object.editmode_toggle()
                bpy.ops.uv.smart_project() 
                bpy.ops.object.editmode_toggle()
            
            
            if context.scene.Up in '0':
                axis = 'X'
            if context.scene.Up in '1':
                axis = 'Y'
            if context.scene.Up in '2':
                axis = 'Z'
                            
            scale = context.scene.ScaleSetting
                      
            #finally export
            newfile_name = os.path.join( filepath_full , obj.name,)

            print(newfile_name)
            if context.scene.Format in '0':
                newfile_name += ".obj"
                bpy.ops.export_scene.obj(filepath=newfile_name, axis_forward='-Z', axis_up=axis , use_materials = context.scene.WriteMaterials, use_selection=True, global_scale = scale, use_triangles = context.scene.Triangulate, use_mesh_modifiers = True)
            if context.scene.Format in '1':
                newfile_name += ".fbx"
                bpy.ops.export_scene.fbx(filepath=newfile_name, axis_forward='-Z', axis_up='Y',use_selection=True, global_scale = scale, use_mesh_modifiers = True)
            
            #back to old position
            obj.location = posOld
        return {"FINISHED"}


class ExportPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Batch Export Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "render"
    # my_bool = bpy.props.BoolProperty(name="Toggle Option")
    
    def draw(self, context):
        layout = self.layout
        scn = context.scene

        row = layout.row()
        row.label(text="Batch Exporter", icon='WORLD_DATA')
    
        row = layout.row()
        split = row.split(percentage=0.25)
        col = split.column()
        col.prop(scn, 'Triangulate')
        
        split = split.split(percentage=0.3)
        col = split.column()
        col.prop(scn, 'LightMap')
        
        split = split.split(percentage=0.4)
        col = split.column()
        col.prop(scn, 'WriteMaterials')
        
        row = layout.row()
        
        split = row.split(percentage=0.7)
        col = split.column()
        col.prop(scn, 'MyEnum')
        
        split = row.split(percentage=0.7)
        col = split.column()
        col.prop(scn, 'Up')   

        row = layout.row()
        split = row.split(percentage=.65)
        col = split.column()
        col.prop(scn, 'ScaleSetting')
           
        split = row.split(percentage=.85)
        col = split.column()
        col.prop(scn,"Root_folder")

        row = layout.row()
        split = row.split(percentage=1)
        col = split.column()
        col.operator("mesh.export_models", text="Export", icon='SCENE')
             
def register():
    bpy.utils.register_class(ExportPanel)
   
def unregister():
    bpy.utils.unregister_class(ExportPanel)
    del bpy.types.Scene.export_objects