2017-02-22 70 views
0

我有这个VEX脚本的问题。 的@是创建attributs而不是变量在列表中添加一个新值

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

}

我想“pavW”价值增加“myList中”如果“pavW”是“myList中”的元素型动物。 结果不如例外。

+0

这是一个烦恼脚本,三维软件的专有langage。它看起来像C. @允许你创建属性,它就像变量,但你可以在3d上下文中使用它们 –

+1

仅仅因为它看起来像C并不意味着它应该被标记C.无论如何,现在一个新的标签是如果您可以链接到参考手册,以便标签描述可以填充,那就太棒了。 – StoryTeller

回答

0

foreach您只是比较array的第一个元素。而对于其他元素,您的if条件将失败并继续添加到myList。你应该pusharrayforeach块以外。

临时变量名为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... 
    } 
} 

建议

  • 你不需要指数foreach
  • 对于这类任务,只需创建一个备用parm并添加Python 表达式即可获取独特的widthPav parm列表。

简单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] 
相关问题