def check_mat_name_unique(name_id="Material_new"):
# check if the new name pattern is in materials' data
name_list = []
suffix = 1
try:
if c_data_has_materials():
name_list = [mat.name for mat in bpy.data.materials if name_id in mat.name]
new_name = "{}_{}".format(name_id, len(name_list) + suffix)
if new_name in name_list:
# KISS failed - numbering is not sequential
# try harvesting numbers in material names, find the rightmost ones
test_num = []
from re import findall
for words in name_list:
test_num.append(findall("\d+", words))
suffix += max([int(l[-1]) for l in test_num])
new_name = "{}_{}".format(name_id, suffix)
return new_name
except Exception as e:
print("\n[Materials Utils Specials]\nfunction: check_mat_name_unique\nError: %s \n" % e)
pass
return name_id
评论列表
文章目录