取决于您要查找的内容,cmds.listHistory
或者cmds.listConnections
会告诉您给定节点的内容。 listHistory
仅限于驱动形状节点更改的可能连接的子集,因此如果您对约束感兴趣,则需要遍历listConnections
节点并查看上游的内容。该列表可以任意大,因为它可能包含许多隐藏节点,例如您可能不想关心的单元翻译、组部分等。
这是控制节点的传入连接并获取传入连接树的简单方法:
def input_tree(root_node):
visited = set() # so we don't get into loops
# recursively extract input connections
def upstream(node, depth = 0):
if node not in visited:
visited.add(node)
children = cmds.listConnections(node, s=True, d=False)
if children:
grandparents = ()
for history_node in children:
grandparents += (tuple(d for d in upstream(history_node, depth + 1)))
yield node, tuple((g for g in grandparents if len(g)))
# unfold the recursive generation of the tree
tree_iter = tuple((i for i in upstream(root_node)))
# return the grandparent array of the first node
return tree_iter[0][-1]
这应该产生一个嵌套的输入连接列表,例如
((u'pCube1_parentConstraint1',
((u'pSphere1',
((u'pSphere1_orientConstraint1', ()),
(u'pSphere1_scaleConstraint1', ()))),)),
(u'pCube1_scaleConstraint1', ()))
其中每个级别都包含一个输入列表。然后,您可以浏览它以查看您提议的更改是否包含该项目。
但是,这不会告诉您连接是否会导致真正的循环:这取决于不同节点内的数据流。一旦你确定了可能的循环,你就可以回去看看循环是真实的(例如,两个项目会影响彼此的翻译)还是无害的(我影响你的轮换,你影响我的翻译)。