From 74b03d24c39809eecf548c392a4b415c44e3b144 Mon Sep 17 00:00:00 2001 From: Olaf Haag Date: Thu, 22 Apr 2021 19:28:44 +0200 Subject: [PATCH] fix critical bug in export --- src/scenemanager/manager.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/scenemanager/manager.py b/src/scenemanager/manager.py index d7cde8e..5f10e7d 100644 --- a/src/scenemanager/manager.py +++ b/src/scenemanager/manager.py @@ -51,6 +51,12 @@ def traverse_tree(node: Any): yield from traverse_tree(child) +def deselect_all() -> None: + """Deselect all objects. Use low-level API instead of relying on bpy.ops.object.select_all operator.""" + for obj in bpy.data.objects: + obj.select_set(False) + + def remove_object(obj: bpy.types.Object): """Remove object from scene. @@ -312,7 +318,7 @@ def import_sort_files(context) -> List[str]: # Since we deleted the last active object, set a new one (or None). context.view_layer.objects.active = armature - bpy.ops.object.select_all(action='DESELECT') + deselect_all() return errors @@ -480,20 +486,25 @@ def execute(self, context): for collection in export_collections: # Export is based on object selections. First, deselect everything. - bpy.ops.object.select_all(action='DESELECT') + deselect_all() # Now only select objects in 1 export collection at any time. for obj in collection.all_objects: + obj.hide_viewport = False + obj.hide_set(False) obj.select_set(True) + context.view_layer.objects.active = None file_path = (Path(bpy.path.abspath(self.export_path)) / collection.name.replace(".", "_")).with_suffix('.glb') try: + # ToDo: Use low-level API for export, not ops. bpy.ops.export_scene.gltf(filepath=str(file_path), use_selection=True, check_existing=False) self.report({'INFO'}, f"Exported combination to {file_path}.") except IOError as e: self.report({'WARNING'}, f"Failed to export file {file_path}.\n{str(e)}") # Error would abort all. continue - bpy.ops.object.select_all(action='DESELECT') + deselect_all() + context.view_layer.objects.active = None return {'FINISHED'} def invoke(self, context, event):