Turning many groups into a single integer attribute

   2927   6   1
User Avatar
Member
14 posts
Joined: April 2017
Offline
Hi,

Quick one here
I have some geometry with many primitive groups. I'd like to create an attribulte “groupid” which will store an index of the group. Say I have 10 groups, so the attribute would be 0 on group1, 1 on group2 etc…

Which node should I use? Attribute Wrangle? But how?

Cheers,
B.
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
Here you go.
Edited by BabaJ - May 29, 2018 15:38:20

Attachments:
Index Groups via Attribute.hiplc (53.2 KB)

User Avatar
Member
14 posts
Joined: April 2017
Offline
Thanks! That's so simple… but one tricky thing is i have over 100 of those primitive groups
Probably should just iterate in vex, should I?

Cheers,
B.
User Avatar
Member
402 posts
Joined: June 2014
Offline
Hi B,

you can use the ‘Name SOP’ to create a primitive attribute from groups. You can do any iterations you wanted using that attribute in for-loops etc… so you may well be able to stop there.

Or if you really want an integer attribute you can look up the index of that new ‘name’ attribute in the “primitivegroups” detail intrinsic attribute (see the attached file). Bear in mind that the ordering of groups is not very easy to keep track of or control if you need to change any groupings upstream, so your integer attribute may not behave as you might expect, depending what you want to do with it.

Hope that helps,
Henry

Attachments:
namefromgroup.hiplc (88.3 KB)

Henry Dean
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
Ok..so I changed it to accomodate large number of groups.

Mind you, this only works if the prims only ever belong to one group,

otherwise they get the last group checked as the indice of the group the prim belongs too.

Of course it's only a minor change to the code if you intend to have a prim/s belong to more than one group.

Attachments:
Index Groups via Attribute_1.hiplc (53.4 KB)

User Avatar
Member
14 posts
Joined: April 2017
Offline
Thanks guys!
I just thought hashing the name attribute will give me a consistent id based on the group name, and that's actually enough of what i need, coz I don't need to go back from the indices to the groups. I need it to help cluster some geometry.

Thanks again!
B.
User Avatar
Member
13 posts
Joined: Dec. 2018
Offline
BabaJ
Ok..so I changed it to accomodate large number of groups.

Mind you, this only works if the prims only ever belong to one group,

otherwise they get the last group checked as the indice of the group the prim belongs too.

Of course it's only a minor change to the code if you intend to have a prim/s belong to more than one group.

This just helped me out! Thanks for posting the file. Really appreciated
  • Quick Links