From 14cf8a8b971f1a09f28420c0a195a724ee39847b Mon Sep 17 00:00:00 2001 From: Tristan Strathearn Date: Sat, 25 Jun 2022 17:27:02 +1000 Subject: [PATCH] fix: fix error/crash in clean_utils utility & add logic for lattice modifiers --- utils/clean_utils.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/utils/clean_utils.py b/utils/clean_utils.py index 4876f94..aa2fb08 100644 --- a/utils/clean_utils.py +++ b/utils/clean_utils.py @@ -44,15 +44,12 @@ def remove_utils(self): removal_count = 0 active_util_object_names = set() - all_scene_objects = [obj for obj in bpy.context.scene.objects if obj.type == 'MESH'] - all_util_objects = get_all_util_objects() - util_mods = ['BOOLEAN', 'ARRAY', 'MIRROR'] - - remove_mods = [] + all_scene_objects = [obj for obj in bpy.context.view_layer.objects if obj.type == 'MESH'] + util_mods = ['BOOLEAN', 'ARRAY', 'MIRROR', 'LATTICE'] for obj in all_scene_objects: - mods = list(obj.modifiers) - for mod in mods: + remove_mods = [] + for mod in obj.modifiers: if mod.type not in util_mods: continue @@ -60,7 +57,8 @@ def remove_utils(self): if mod.show_viewport and mod.object: active_util_object_names.add(mod.object.name) else: - remove_mods.append((obj, mod)) + remove_mods.append(mod) + removal_count += 1 continue if mod.type == 'ARRAY': @@ -68,25 +66,28 @@ def remove_utils(self): active_util_object_names.add(mod.offset_object.name) continue + if mod.type == 'LATTICE': + if mod.object: + active_util_object_names.add(mod.object.name) + continue + if mod.type == 'MIRROR': if mod.mirror_object: active_util_object_names.add(mod.mirror_object.name) continue + + for mod in remove_mods: + obj.modifiers.remove(mod) + all_util_objects = get_all_util_objects() + deleted_objects = [] + for obj in all_util_objects: - if obj.name not in active_util_object_names: - try: - bpy.data.objects.remove(obj, do_unlink=True) - removal_count += 1 - except: - pass - - for obj, mod in remove_mods: - try: - obj.modifiers.remove(mod) + if obj and obj.name not in active_util_object_names: + deleted_objects.append(obj) removal_count += 1 - except: - pass + + bpy.ops.object.delete({'active_object': None, 'object': None, 'selected_objects': deleted_objects}, use_global=False) return removal_count