diff --git a/bseq/__init__.py b/bseq/__init__.py index 864fe88..114296c 100644 --- a/bseq/__init__.py +++ b/bseq/__init__.py @@ -12,9 +12,13 @@ @persistent def BSEQ_initialize(scene): if update_obj not in bpy.app.handlers.frame_change_post: + bpy.app.handlers.frame_change_post.append(update_obj) + if auto_refresh_active not in bpy.app.handlers.frame_change_post: bpy.app.handlers.frame_change_post.append(auto_refresh_active) + if auto_refresh_all not in bpy.app.handlers.frame_change_post: bpy.app.handlers.frame_change_post.append(auto_refresh_all) - bpy.app.handlers.frame_change_post.append(update_obj) + if clean_unused_bseq_data not in bpy.app.handlers.save_pre: + bpy.app.handlers.save_pre.append(clean_unused_bseq_data) subscribe_to_selected() if print_information not in bpy.app.handlers.render_init: bpy.app.handlers.render_init.append(print_information) diff --git a/bseq/globals.py b/bseq/globals.py index 5536bfe..3a7ef10 100644 --- a/bseq/globals.py +++ b/bseq/globals.py @@ -51,4 +51,14 @@ def auto_refresh_active(scene, depsgraph=None): continue if obj.mode != "OBJECT": continue - refresh_obj(obj, scene) \ No newline at end of file + refresh_obj(obj, scene) + +# This becomes necessary, because when deleting objects from the viewport, they dont actually get removed from the +# sequences list, because this is not a global delete. This handler only removes sequences that are not referenced +# in any scene or collection. This handler is added to save_pre, so that unused data blocks dont get saved +def clean_unused_bseq_data(savefile): + for obj in bpy.data.objects: + if obj.BSEQ.init and len(obj.users_collection)==0 and len(obj.users_scene)==0: + + # This will throw an error if it is actually still used somewhere + bpy.data.objects.remove(obj) \ No newline at end of file diff --git a/bseq/panels.py b/bseq/panels.py index d7fc270..6fdd6b1 100644 --- a/bseq/panels.py +++ b/bseq/panels.py @@ -13,7 +13,7 @@ def filter_items(self, context, data, property): # not sure if I understand correctly about this # see reference from https://docs.blender.org/api/current/bpy.types.UIList.html#advanced-uilist-example-filtering-and-reordering for o in objs: - if o.BSEQ.init: + if o.BSEQ.init and len(o.users_collection)>0 and len(o.users_scene)>0: flt_flags.append(self.bitflag_filter_item) else: flt_flags.append(0)