代码之家  ›  专栏  ›  技术社区  ›  Soviut

如何在不知道约束类型的情况下查询任何约束的目标列表?

  •  2
  • Soviut  · 技术社区  · 16 年前

    在maya中,我有一个由以下代码收集的约束列表。我要迭代约束并查询每个约束的目标:

    cons = ls(type='constraint')
    for con in cons:
        targets = constraint(query=True, targetList=True)
    

    问题是,没有一般 constraint 用于操作所有约束的命令。相反,每个约束都有自己独特的与之相关联的MEL命令。

    是否有任何方法可以查询约束上的目标,而无需输入检查每个约束并冗长地运行其各自的MEL命令?

    1 回复  |  直到 10 年前
        1
  •  2
  •   Soviut    10 年前

    列出.target属性上的连接

    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" );
    }