import FreeCAD as App
from helper.file_system_repository import FileSystemRepository
from scenarios.robossembler_freecad_export_scenari import (
    RobossemblerFreeCadExportScenario,
)


import FreeCADGui as Gui


import FreeCAD as App

import os


def main():
    try:
        print(os.path.join(os.path.dirname(__file__)) + "/env.json")
        env = FileSystemRepository.readJSON(
            os.path.join(os.path.dirname(__file__)) + "/env.json"
        )
        App.openDocument(env.get("cadFilePath"))
        RobossemblerFreeCadExportScenario.call(env.get("outPath"))
        App.closeDocument(App.ActiveDocument.Name)
        freecadQTWindow = Gui.getMainWindow()
        freecadQTWindow.close()
    except ValueError:
        freecadQTWindow = Gui.getMainWindow()
        freecadQTWindow.close()


main()
