0

我对这个 VEX 脚本有疑问。 @创建属性而不是变量。

f[]@myList; // create list attribut
float pavW = 0.0;
for( int i = 1 ; i < 11 ; i++){
    string path = "../widthPav" + itoa(i);
    pavW = ch(path); // take the value in the specific channel
    if (i == 1){
        push(@myList,pavW); //add new component of value to myList
    }
    if ( pavW > 0){
        foreach ( int j ; float value ; @myList){
            if ( pavW == value){
                break;
            }else{
                push(@myList,pavW); //add new component...
                break;
            }
        }
    }

}

我想为 pavWifmyListpavW元素与myList. 结果并不如预期。

4

1 回答 1

1

foreach您仅与第一个元素进行比较array。对于其他元素,您的if条件失败并继续添加到myList. 你应该pusharray外面的foreach街区。

一个名为的临时变量unique可用于触发push.

f[]@myList; // create list attribut
float pavW = 0.0;
for (int i = 1; i < 11; i++)
{
    string path = "widthPav" + itoa(i);
    pavW = ch(path); // take the value in the specific channel
    if (i == 1)
    {
        push(@myList, pavW); //add new component of value to myList
    }
    if (pavW > 0)
    {
        int unique = 0;
        foreach (float value; @myList)
        {
            unique = 1;
            if (pavW == value)
            {
                unique = 0;
                break;
            }
        }
        if (unique)
            push(@myList, pavW); //add new component...
    }
}

建议

  • 您不需要索引 in foreach
  • 对于此类任务,只需创建一个备用参数并添加一个Python 表达式以获取唯一参数列表widthPav

简单Python的片段:

node = hou.pwd()
parmsUniqueValue = []

[parmsUniqueValue.append(parm.eval()) for parm in node.parms() if parm.name().startswith('widthPav') if parm.eval() not in parmsUniqueValue]  
于 2017-04-16T18:55:20.803 回答