diff options
author | Bastien Montagne <b.mont29@gmail.com> | 2020-02-13 19:46:57 +0300 |
---|---|---|
committer | Bastien Montagne <b.mont29@gmail.com> | 2020-02-13 19:46:57 +0300 |
commit | dadabf5cf3babfbda5075bd7093909ca01655b9e (patch) | |
tree | 5b8849555048c9bfb411c1a8820b68383e8e7503 /source/blender/python | |
parent | 92e41bb1a8a540e8f1f5abdd4127647815ebb22c (diff) |
Py API: Add `orphans_purge` helper to `bpy.data`.
Much more convinient than trying to use outliner operator...
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_rna_id_collection.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_rna_id_collection.c b/source/blender/python/intern/bpy_rna_id_collection.c index e1d5c358ba5..ca5cb287401 100644 --- a/source/blender/python/intern/bpy_rna_id_collection.c +++ b/source/blender/python/intern/bpy_rna_id_collection.c @@ -348,6 +348,43 @@ error: return ret; } +PyDoc_STRVAR(bpy_orphans_purge_doc, + ".. method:: orphans_purge()\n" + "\n" + " Remove (delete) all IDs with no user.\n" + "\n" + " WARNING: Considered experimental feature currently.\n"); +static PyObject *bpy_orphans_purge(PyObject *UNUSED(self), + PyObject *UNUSED(args), + PyObject *UNUSED(kwds)) +{ +#if 0 /* If someone knows how to get a proper 'self' in that case... */ + BPy_StructRNA *pyrna = (BPy_StructRNA *)self; + Main *bmain = pyrna->ptr.data; +#else + Main *bmain = G_MAIN; /* XXX Ugly, but should work! */ +#endif + + ID *id; + FOREACH_MAIN_ID_BEGIN (bmain, id) { + if (id->us == 0) { + id->tag |= LIB_TAG_DOIT; + } + else { + id->tag &= ~LIB_TAG_DOIT; + } + } + FOREACH_MAIN_ID_END; + + 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; +} + int BPY_rna_id_collection_module(PyObject *mod_par) { static PyMethodDef user_map = { @@ -365,5 +402,15 @@ int BPY_rna_id_collection_module(PyObject *mod_par) PyModule_AddObject( mod_par, "_rna_id_collection_batch_remove", PyCFunction_New(&batch_remove, NULL)); + static PyMethodDef orphans_purge = { + "orphans_purge", + (PyCFunction)bpy_orphans_purge, + METH_VARARGS | METH_KEYWORDS, + bpy_orphans_purge_doc, + }; + + PyModule_AddObject( + mod_par, "_rna_id_collection_orphans_purge", PyCFunction_New(&orphans_purge, NULL)); + return 0; } |