Skip to content

Commit

Permalink
BUGFIX: Selected objects are not preserved after export
Browse files Browse the repository at this point in the history
  • Loading branch information
ulasozguler committed May 4, 2022
1 parent 38e0b5d commit 56d5b03
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 56d5b03

Please sign in to comment.