From 56d5b0342196eff9e327cd18e399fc8d0b64bf97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20=C3=96zg=C3=BCler?= Date: Wed, 4 May 2022 11:22:44 +0300 Subject: [PATCH] BUGFIX: Selected objects are not preserved after export --- src/core.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/core.py b/src/core.py index 863486b..77c87af 100644 --- a/src/core.py +++ b/src/core.py @@ -2,6 +2,20 @@ import bpy +def preserve_selection(func): + def inner(*args, **kwargs): + orig_selected_objs = bpy.context.selected_objects + try: + return func(*args, **kwargs) + finally: + bpy.ops.object.select_all(action="DESELECT") + for o in orig_selected_objs: + o.select_set(True) + + return inner + + +@preserve_selection def export_objects(objects, folder, object_types): for an_obj in objects: bpy.ops.object.select_all(action="DESELECT") @@ -28,7 +42,9 @@ def export_objects(objects, folder, object_types): bpy.ops.object.delete() +@preserve_selection def export_collections(parent_collection, folder, object_types): + for coll in parent_collection.children: if len(coll.all_objects) == 0: # skip empty collections continue