我对Python有点新手,我正在尝试使用maya中的父对象,具体取决于他们的名字。示例我在场景中有“spineA_jnt”,“spineB_jnt”,“spineC_jnt”和“spineA_jb”,“spineB_jb”,“spineC_jb”。如何选择它们并将父“spineA_jnt”添加到“spineA_jb”等等。任何提示都会非常感谢,谢谢。
答案 0 :(得分:0)
您可以使用字典:
spines = "spineA_jnt", "spineB_jnt", "spineC_jnt", "spineA_jb", "spineB_jb", "spineC_jb"
def group_spines(spines):
spine_dict = {}
for spine in spines:
parts = spine.split('_')
if parts[0] in spine_dict:
spine_dict[parts[0]].append(spine)
else:
spine_dict[parts[0]]=[spine]
return spine_dict
spine_dict = group_spines(spines)
# results of group_spines function
{'spineA': ['spineA_jnt', 'spineA_jb'],
'spineB': ['spineB_jnt', 'spineB_jb'],
'spineC': ['spineC_jnt', 'spineC_jb']}
final_result = dict(spine_dict.values())
# now we have parented the spine parts together
{'spineA_jnt': 'spineA_jb',
'spineB_jnt': 'spineB_jb',
'spineC_jnt': 'spineC_jb'}