Gather all the different string names on my primitives

   2346   4   1
User Avatar
Member
1004 posts
Joined: April 2017
Offline
Hi!

I have primitives with string attribute: subset_A, subset_B, subset_C. I would like a detail wrangle to check all the string attribute it found and put them in an array.

My current method would end up with duplicates: .

Is there an easy way to only have one of each in my array? Or do I have to go over each value and compare to all other values found… ?

-Olivier
User Avatar
Member
8531 posts
Joined: July 2007
Online
this will return array of all unique values of string or int attribute
https://www.sidefx.com/docs/houdini/vex/functions/uniquevals.html [www.sidefx.com]
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
1004 posts
Joined: April 2017
Offline
Thanks!

That sounds like a great function. Sadly, I don't have access to it in my Houdini 16. I found a workaround for anybody interested. The trick was to sort my array values before cleaning up the duplicates:


int nprims = nprimitives(0);
string curValue; //aka current value used
string allValues[];
// simply placing all values in an array
for(int i=0; i<nprims; i++)
    {
    curValue = prim(0, "subset", i);
    push(allValues, curValue);
    }
sort(allValues); //a long array containing lots of duplicates but all sorted

// cleaning (removing duplicates)
string storedValue = allValues[0]; //storing first value
string cleanedValues[];
push(cleanedValues, allValues[0]); //I need one value to begin

for(int i=0; i<nprims; i++)
    {
    curValue = prim(0, "subset", i);
    if(storedValue != curValue)
        {
        push(cleanedValues, curValue);
        storedValue = curValue;
        }
    }
User Avatar
Member
8531 posts
Joined: July 2007
Online
olivierth
That sounds like a great function. Sadly, I don't have access to it in my Houdini 16
then just use nuniqueval() and uniqueval(), I'm pretty sure those are in H16
string attrib = "subset";
int count = nuniqueval(0, "prim", attrib);
for (int i=0; i<count; i++){
    string value = uniqueval(0, "prim", attrib, i);
    append(s[]@unique, value);
}

again for completness in 17.0 it would just be:
string attrib = "subset";
s[]@unique = uniquevals(0, "prim", attrib);
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
1004 posts
Joined: April 2017
Offline
Ah! thanks for the info!

-Olivier
  • Quick Links