python - 如何在 Maya python 中获取父关节组
问题描述
我有这样的层次结构:
root_ctrl
group2
group3
joint
我想获取组的名称。
输出应该是['group2', 'group3']
. 我试过使用
parents = cmds.listRelatives('joint', allParents = True )
output = []
parents = (cmds.ls('joint', long=True)[0].split('|')[1:-1])
print parents
但这会返回 [join,group3,group2,root_ctrl]。但我想 [group3, group2] 作为输出。
解决方案
如果我了解您的问题,这是一个解决方案。这是一个不是很漂亮的解决方案,但它仍然有效。
hierarchy = cmds.ls('joint', long=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))
推荐阅读
- python - 当您的数据输入频率与数据输出频率不同时,如何准备您的训练数据输入
- php - Yii2 时区:日期列根据格式更改值
- javascript - 使用带有部分 HTML 按钮的 onclick
- javascript - 在大型文档中搜索所有电子邮件
- swift - NSWindowController:如何只打开一次:状态栏中的 macOS 应用程序
- amazon-web-services - AWS RDS 磁盘空间使用百分比
- python - 解析 XML 文件并针对 xsd 模式进行验证
- wso2 - 将 WSO2_CARBON_DB 从 H2 更改为 MySql
- c# - 如何使用 .NET Core 在多个远程服务器上执行 IISReset?
- uwp - 如何使用 RichTextBlock 显示 html 格式