45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
|
#!/usr/bin/env python
|
|||
|
# -*- coding: utf-8 -*-
|
|||
|
|
|||
|
"""
|
|||
|
版权所有: 深圳时光科技有限公司
|
|||
|
联系方式: q.100@qq.com
|
|||
|
创建日期: 2023/08/08
|
|||
|
"""
|
|||
|
|
|||
|
import maya.cmds as cmds
|
|||
|
|
|||
|
def sg_rename_blend_shapes():
|
|||
|
"""
|
|||
|
重命名所有网格的混合变形目标
|
|||
|
遍历前50个网格,为每个混合变形目标添加网格名称前缀
|
|||
|
"""
|
|||
|
# 遍历前50个网格
|
|||
|
for j in range(50):
|
|||
|
# 获取网格名称
|
|||
|
mesh = cmds.SGGetMeshes(i=j)
|
|||
|
blend_shape = f"{mesh}_blendShapes"
|
|||
|
|
|||
|
# 检查混合变形器是否存在
|
|||
|
if cmds.objExists(blend_shape):
|
|||
|
# 获取所有权重属性
|
|||
|
attr_weight = f"{blend_shape}.weight"
|
|||
|
current_blend_shape_list = cmds.listAttr(attr_weight, m=True)
|
|||
|
|
|||
|
# 遍历每个混合变形目标
|
|||
|
for i, bs_name in enumerate(current_blend_shape_list):
|
|||
|
# 检查是否已经有正确的前缀
|
|||
|
if not bs_name.startswith(f"{mesh}__"):
|
|||
|
try:
|
|||
|
# 重命名混合变形目标
|
|||
|
cmds.aliasAttr(
|
|||
|
f"{mesh}__{bs_name}",
|
|||
|
f"{blend_shape}.w[{i}]"
|
|||
|
)
|
|||
|
except:
|
|||
|
# 忽略重命名失败的情况
|
|||
|
pass
|
|||
|
|
|||
|
# 如果直接运行此脚本
|
|||
|
if __name__ == '__main__':
|
|||
|
sg_rename_blend_shapes()
|