import bpy from sys import argv from pathlib import Path blends_folder = (Path(bpy.path.abspath(bpy.data.texts["export.py"].filepath))/"..").resolve() blend_path = Path(bpy.path.abspath(bpy.context.blend_data.filepath)).relative_to(blends_folder) godot_folder = (Path(bpy.path.abspath(bpy.data.texts["export.py"].filepath))/".."/".."/"godot").resolve() export_file = str((godot_folder/blend_path).resolve()).replace(".blend", ".glb") def export(path: str): bpy.ops.object.mode_set(mode="OBJECT") bpy.context.view_layer.update() # Clear the selection for target in bpy.context.selected_objects: target.select_set(False) collection = bpy.data.collections["export"] for target in collection.objects: target.select_set(True) bpy.context.view_layer.update() bpy.ops.export_scene.gltf( filepath=path, export_format="GLB", use_selection=True, export_colors=False, export_apply=True, export_animation_mode="NLA_TRACKS", export_anim_slide_to_zero=True, ) try: i = next((i for i, arg in enumerate(argv) if arg == "--export-path"), None) if i is None: path = export_file else: path = str(Path(argv[i+1]).resolve()) export(path) print("Export successful") if bpy.app.background: quit(0) except SystemExit as e: quit(e.code) except: import traceback traceback.print_exc()