From 73565fa83ec229686a529af6e8f34d51d11385af Mon Sep 17 00:00:00 2001 From: "demeterdzadik@gmail.com" Date: Mon, 10 Jul 2023 10:46:15 +0200 Subject: [PATCH] Blender Purge: use_fake_user=False for linked IDs ...and collections. --- .../blender_crawl/default_scripts/purge.py | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/blender-crawl/blender_crawl/default_scripts/purge.py b/scripts/blender-crawl/blender_crawl/default_scripts/purge.py index f282e18f..96e1a580 100644 --- a/scripts/blender-crawl/blender_crawl/default_scripts/purge.py +++ b/scripts/blender-crawl/blender_crawl/default_scripts/purge.py @@ -20,5 +20,29 @@ # (c) 2021, Blender Foundation import bpy -bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True) + + +def better_purge(context, clear_coll_fake_users=True): + """Call Blender's purge function, but first Python-override all library IDs' + use_fake_user to False. + Otherwise, linked IDs essentially do not get purged properly. + + Also set all Collections' use_fake_user to False, so unused collections + aren't kept in the file. + """ + + if clear_coll_fake_users: + for coll in bpy.data.collections: + coll.use_fake_user = False + + id_list = list(bpy.data.user_map().keys()) + for id in id_list: + if id.library: + id.use_fake_user = False + + bpy.ops.outliner.orphans_purge( + do_local_ids=True, do_linked_ids=True, do_recursive=True) + + +better_purge() bpy.ops.wm.quit_blender() -- 2.30.2