如何在Maya python中获得父级关节组

问题描述 投票:-1回答:1

我具有这样的层次结构:

group2
  group3
    joint

我想获取组名。输出应为['group2', 'group3']

python parent maya
1个回答
0
投票

如果我了解您的问题,这是一种解决方案。这不是一个非常漂亮的解决方案,但是它已经可以工作了。

hierarchy = cmds.listRelatives('Joint', fullPath=True)[0]

def get_groups(hierarchy=None):
    nodes = [node for node in hierarchy.split('|') if node]
    return [x for x in nodes if cmds.listRelatives(x, shapes=True) is None and cmds.nodeType(x) == 'transform']

print(get_groups(hierarchy))
© www.soinside.com 2019 - 2024. All rights reserved.