def optimize_scenery(script_settings):
    try:
        # instantiate the msfsProject and create the necessary resources if it does not exist
        msfs_project = MsfsProject(script_settings.projects_path,
                                   script_settings.project_name,
                                   script_settings.definition_file,
                                   script_settings.author_name,
                                   script_settings.sources_path)

        check_configuration(
            script_settings,
            msfs_project,
            check_optimisation=True,
            check_lily_texture_packer=script_settings.bake_textures_enabled)

        if script_settings.backup_enabled:
            msfs_project.backup(
                Path(os.path.abspath(__file__)).stem.replace(
                    SCRIPT_PREFIX, str()))

        clean_scene()
        msfs_project.optimize(script_settings)

        if script_settings.build_package_enabled:
            build_package(msfs_project, script_settings)

        pr_bg_green("Script correctly applied" + CEND)

    except ScriptError as ex:
        error_report = "".join(ex.value)
        isolated_print(constants.EOL + error_report)
        pr_bg_red("Script aborted" + CEND)
    except RuntimeError as ex:
        isolated_print(constants.EOL + str(ex))
        pr_bg_red("Script aborted" + CEND)
    def __extract_splitted_tiles(self, min_size_value, tile):
        for key, node in self.splitted_nodes.items():
            splitted_tile_name = key.split("_")[0]

            import_model_files([os.path.join(self.folder, self.model_file)])
            model_file_path = os.path.join(self.folder, key + GLTF_FILE_EXT)
            extract_splitted_tile(model_file_path, node, TEXTURE_FOLDER)
            self.prepare_for_msfs(model_file_path=model_file_path)

            if not os.path.isfile(os.path.join(self.folder, splitted_tile_name + XML_FILE_EXT)):
                new_guid = create_new_definition_file(os.path.join(self.folder, splitted_tile_name + XML_FILE_EXT))
                tile.new_tiles[new_guid] = os.path.join(self.folder, splitted_tile_name + XML_FILE_EXT)
            if self.lod_level < (len(tile.lods) - 1):
                add_new_lod(os.path.join(self.folder, splitted_tile_name + XML_FILE_EXT), key + GLTF_FILE_EXT, min_size_value)

        clean_scene()
            "Error: --folder=\"some string\" argument not given, aborting.")

    if not args.name:
        raise ScriptError(
            "Error: --name=\"some string\" argument not given, aborting.")

    if not args.definition_file:
        raise ScriptError(
            "Error: --definition_file=\"some string\" argument not given, aborting."
        )

    if not args.objects_xml_folder:
        raise ScriptError(
            "Error: --objects_xml_folder=\"some string\" argument not given, aborting."
        )

    if not args.objects_xml_file:
        raise ScriptError(
            "Error: --objects_xml_file=\"some string\" argument not given, aborting."
        )

    clean_scene()

    settings = Settings(get_sources_path())
    check_lily_texture_packer_availability(settings)

    tile = MsfsTile(args.folder, args.name, args.definition_file)
    tile.split(settings)
except:
    pass