How to create groups based upon duplicate attribute values [SOLVED]

   2305   3   0
User Avatar
Member
7 posts
Joined: March 2017
Offline
My first serious project has hit the buffers and I wonder if i could please get some pointers to move forward. I need to form a set of groups dynamically based upon duplicate attribute values. Each group must consist only of duplicates or only a single primitive if there are no duplicates. Ideally I wish to store the result in another attribute but forming a group for each set of duplicates will suffice. How to get this done most efficiently? I need a “Group by Duplicate attribute” SOP or VEX wrangle equivalent but just cant quite get the code logic right as my screenshot shows.


Specifically in the below annotation I need the values listed in perimInt (right column) to be allocated a sequential mesh ID (2nd from right column) based upon descending order of size ( these relate to perimeter size of each primitive by colour) , so primitives 0-1 should be meshID 0, primitive 3 is meshID 1, primatives 3-4 is MeshID 2 etc

I have tried the partition SOP to create the groups but the rule syntax is problematic if you do not know in advance the attribute values you are grouping against. I am a VEX newbie so have tried to write my own wrangle but have underestimated the programming complexity of the task which i initially thought would be straightforward. Any helpful suggestions gratefully appreciated.
Edited by PaulJChris - April 28, 2020 16:44:45

Attachments:
houdinicapture.JPG (386.4 KB)

User Avatar
Member
7 posts
Joined: March 2017
Offline
Never mind. managed to solve it in a Wrangle by just rethinking the logic. I was over thinking it. This simple code works for my attribute list provided it has been sorted into descending order by the preceding Sort node.
Edited by PaulJChris - April 28, 2020 16:41:54

Attachments:
houdini2.JPG (31.0 KB)

User Avatar
Member
8597 posts
Joined: July 2007
Offline
or you can just do this, including the sorting
Prim Wrangle:
int vals[] = uniquevals(0, "prim", "perimInt");
vals = sort(vals);
vals = reverse(vals);
i@meshID = find(vals, i@perimInt); 
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
7 posts
Joined: March 2017
Offline
tamte
or you can just do this, including the sorting
Prim Wrangle:
int vals[] = uniquevals(0, "prim", "perimInt");
vals = sort(vals);
vals = reverse(vals);
i@meshID = find(vals, i@perimInt); 

Elegance personified Tomas ,thank you, that is so much better and removes a node as well. Vex knowledge++
  • Quick Links