diff options
-rw-r--r-- | source/blender/blenkernel/BKE_library.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 19 |
2 files changed, 21 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 16e05cd136a..50447e02fe5 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -201,6 +201,8 @@ void BKE_main_lib_objects_recalc_all(struct Main *bmain); /* (MAX_ID_NAME - 2) + 3 */ void BKE_id_ui_prefix(char name[66 + 1], const struct ID *id); +char *BKE_id_to_unique_string_key(const struct ID *id); + void BKE_library_free(struct Library *lib); void BKE_library_make_local( diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 08d68f4a480..06207eabe31 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -2535,6 +2535,25 @@ void BKE_id_ui_prefix(char name[MAX_ID_NAME + 1], const ID *id) strcpy(name + 3, id->name + 2); } +/** + * Returns an allocated string concatenating ID name (including two-chars type code) and its lib name if any, + * which is expected to be unique in a given Main database.. + */ +char *BKE_id_to_unique_string_key(const struct ID *id) +{ + const size_t key_len_base = strlen(id->name) + 1; + const size_t key_len_ext = ((id->lib != NULL) ? strlen(id->lib->name) : 0) + 1; + const size_t key_len = key_len_base + key_len_ext - 1; + char *key = MEM_mallocN(key_len, __func__); + + BLI_strncpy(key, id->name, key_len_base); + if (id->lib != NULL) { + BLI_strncpy(key + key_len_base - 1, id->lib->name, key_len_ext); + } + + return key; +} + void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath) { /* in some cases this is used to update the absolute path from the |