diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-01-06 21:34:42 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-01-06 21:48:10 +0300 |
commit | 4acf0f05a1ec0b96c4a2e9c3628190f52a3590e2 (patch) | |
tree | 6c58b90f9133ce30d3e7b125181c5c267885b698 /source/blender/makesrna/intern/rna_ID.c | |
parent | ea7a2766f6054bf991dee746408f45c535c324b5 (diff) |
'users of ID' py API.
This mainly adds bpy.data.user_map() method, which goes over the whole Main database
to build a mapping (dict) {ID: {users_of_that_ID}}.
Very handy to check and debug ID usages, but could also be really valuable for py addons
creating temporary scenes, or some exporters, etc.
Note: current code in master's libquery misses some IDs (and reports some it should not,
like nodetrees), this is fixed in id-remap but still needs serious review before going to master.
This basically means that current bpy.data.user_map() **will not** report a complete and exhaustive
state of dependencies between IDs. Should work OK in most cases though.
Original work/idea comes from id-remap branch, was heavily reworked by @campbellbarton
and myself for master.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D1678
Diffstat (limited to 'source/blender/makesrna/intern/rna_ID.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_ID.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 3a163300264..63ea836e3de 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -90,6 +90,7 @@ EnumPropertyItem rna_enum_id_type_items[] = { #include "BKE_font.h" #include "BKE_idprop.h" #include "BKE_library.h" +#include "BKE_library_query.h" #include "BKE_animsys.h" #include "BKE_material.h" #include "BKE_depsgraph.h" @@ -976,6 +977,14 @@ static void rna_def_ID(BlenderRNA *brna) RNA_def_function_ui_description(func, "Clear the user count of a data-block so its not saved, " "on reload the data will be removed"); + func = RNA_def_function(srna, "user_of_id", "BKE_library_ID_use_ID"); + RNA_def_function_ui_description(func, "Count the number of times that ID uses/references given one"); + parm = RNA_def_pointer(func, "id", "ID", "", "ID to count usages"); + RNA_def_property_flag(parm, PROP_NEVER_NULL); + parm = RNA_def_int(func, "count", 0, 0, INT_MAX, + "", "Number of usages/references of given id by current datablock", 0, INT_MAX); + RNA_def_function_return(func, parm); + func = RNA_def_function(srna, "animation_data_create", "rna_ID_animation_data_create"); RNA_def_function_flag(func, FUNC_USE_MAIN); RNA_def_function_ui_description(func, "Create animation data to this ID, note that not all ID types support this"); |