import sys
import os
import bpy
from math import pi

dirname = sys.argv[5]

os.chdir(dirname)


source_filename = dirname + '_zup.dae'
dest_filename = dirname + '_v2.dae'

bpy.ops.wm.collada_import(filepath=source_filename, import_units=False, fix_orientation=True)

bpy.ops.transform.rotate(value=pi/2.0, axis=(1,0,0), constraint_orientation='GLOBAL')
bpy.ops.transform.rotate(value=pi/2.0, axis=(0,0,1), constraint_orientation='GLOBAL')

bpy.ops.object.transform_apply(rotation=True)

bpy.ops.wm.collada_export(filepath=dest_filename)


bpy.ops.object.select_all(action='TOGGLE')
bpy.ops.object.select_all(action='TOGGLE')

d = bpy.context.selected_objects[1].dimensions
print("Size = {}, {}, {} (m)".format(d[0], d[1], d[2]))

os.chdir("..")


