如何在不知道约束类型的情况下查询约束的目标列表?
在Maya软件中,我有一个通过以下代码收集到的约束列表。我想要遍历这些约束,并查询每个约束的目标对象:
cons = ls(type='constraint')
for con in cons:
targets = constraint(query=True, targetList=True)
问题是,没有一个通用的constraint
命令可以用来操作所有的约束。每个约束都有自己独特的MEL命令。
有没有什么办法可以查询一个约束的目标,而不需要逐个检查每个约束并繁琐地运行它们各自的MEL命令呢?
1 个回答
2
在 .target 属性上使用 listConnections
在 mel 中的清理工作:
string $cons[] = `ls -type "constraint"`;
for ( $con in $cons ){
string $targetAttrString = ( $con+ ".target" );
string $connections[] = `listConnections $targetAttrString`;
string $connectionsFlattened[] = stringArrayRemoveDuplicates($connections);
for ( $f in $connectionsFlattened )
if ( $f != $con )
print ( $f+ " is a target\n" );
}