我的选择可以合理地包含大多数任何节点类型。在python中,我需要过滤掉除组节点以外的所有内容。问题在于,maya将组节点作为变换节点读取,因此事实证明很难将其从场景中的所有其他变换节点中滤除。有没有办法做到这一点?可能在API中?
谢谢!
正如您所提到的,“组”节点实际上只是transform
节点,没有真正的区别。
但是,我能想到的最明显的区别是它的子级必须完全由其他transform
节点组成。将形状节点作为“组”下的父级将不再被视为“组”
首先,选择transform
节点。我认为您已经有以下几方面的东西:
selection = pymel.core.ls(selection=True, transforms=True)
接下来,检查给定转换本身是否为“组”的函数。
遍历给定节点的所有子节点,False
如果没有子节点,则返回transform
。否则返回True
。
def is_group(node):
children = node.getChildren()
for child in children:
if type(child) is not pymel.core.nodetypes.Transform:
return False
return True
现在,您只需要使用以下两种方法之一来过滤选择,具体取决于您最清楚的样式:
selection = filter(is_group, selection)
或者
selection = [node for node in selection if is_group(node)]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句