__init__.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:bpy_lambda 作者: bcongdon 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号