0

I have a problem with this VEX script. @ create attributes instead of variables.

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

}

I want to add pavW value to myList if pavW is different than the elements of myList. The result is not as expected.

Doug Richardson
  • 10,483
  • 6
  • 51
  • 77
Vincent A
  • 85
  • 10
  • it's a vex script , a proprietary langage of a 3d software. it looks like C. @ allows you to create attributes , it's like variables but you can use them in the 3d context – Vincent A Feb 22 '17 at 10:06
  • 1
    Just because it looks like C doesn't mean it should be tagged C. Anyway, now that a new tag is created, if you could kindly link to a reference manual so the tag description could be populated, it would be great. – StoryTeller - Unslander Monica Feb 22 '17 at 10:08

1 Answers1

1

In foreach you are comparing to the first element of array only. And for other elements your if conditions fails and keeps on adding to the myList. You should push to the array outside foreach block.

A temporary var named unique can be used to trigger the 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...
    }
}

Suggestions:

  • You don't need index in foreach.
  • For this kind of task, simply create an spare parm and add a Python expression to get list of unique widthPav parm.

Simple Python snippet:

node = hou.pwd()
parmsUniqueValue = []

[parmsUniqueValue.append(parm.eval()) for parm in node.parms() if parm.name().startswith('widthPav') if parm.eval() not in parmsUniqueValue]  
PradeepBarua
  • 37
  • 1
  • 12