diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2020-12-22 16:05:49 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2020-12-22 16:05:49 +0300 |
commit | 2601501fce554290d9245fdbcb536c7c87c73f11 (patch) | |
tree | a077501b38cddabfe5158e3d886ae55ce7606495 /source/blender/python | |
parent | 512a23c3d61d3ac454e9c098ddbf1d0d3beb19a0 (diff) |
RNA: make `bpy.data.orphans_purge()` return number of deleted datablocks
Sometimes multiple calls to `bpy.data.orphans_purge()` are needed to
delete all orphans, because a call can turn previously-used datablocks
into orphans. Returning the number of deleted datablocks makes it
possible to keep looping until nothing can be deleted any more.
This patch keeps track of deletions in `id_delete()` so that it can be
returned up the call stack.
Reviewed By: mont29
Differential Revision: https://developer.blender.org/D9918
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_rna_id_collection.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/source/blender/python/intern/bpy_rna_id_collection.c b/source/blender/python/intern/bpy_rna_id_collection.c index a4df8c3aef1..bf6eba93b9f 100644 --- a/source/blender/python/intern/bpy_rna_id_collection.c +++ b/source/blender/python/intern/bpy_rna_id_collection.c @@ -353,6 +353,8 @@ PyDoc_STRVAR(bpy_orphans_purge_doc, "\n" " Remove (delete) all IDs with no user.\n" "\n" + " :return: The number of deleted IDs.\n" + "\n" " WARNING: Considered experimental feature currently.\n"); static PyObject *bpy_orphans_purge(PyObject *UNUSED(self), PyObject *UNUSED(args), @@ -376,13 +378,11 @@ static PyObject *bpy_orphans_purge(PyObject *UNUSED(self), } FOREACH_MAIN_ID_END; - BKE_id_multi_tagged_delete(bmain); + const size_t num_datablocks_deleted = BKE_id_multi_tagged_delete(bmain); /* Force full redraw, mandatory to avoid crashes when running this from UI... */ WM_main_add_notifier(NC_WINDOW, NULL); - Py_INCREF(Py_None); - - return Py_None; + return PyLong_FromSize_t(num_datablocks_deleted); } PyMethodDef BPY_rna_id_collection_user_map_method_def = { |