Group objects by common partial name matches

   2487   4   2
User Avatar
Member
2 posts
Joined: April 2015
Offline
Not sure if I my ask is using the correct description. Hopefully the image will help explain. I am trying to run a for each over geo that has a bunch of names. Or create groups from each common name block, and then be able to run a for each group etc. The names have common syntax but are not identical. So instead of having 4 "Lace" names I'd love to figure out how to group them to 1 "Lace" group.

Another issue is that I'd like to be able to do this with out knowing what names are present. I know that I can create groups if I already know the partial name, midsole, lace etc. using something like "@name=*ace*" But if I don't know those names. Is there a way to find the common name string and group them.

I hope this is making sense.

Attachments:
name groups.png (566.8 KB)

User Avatar
Member
294 posts
Joined: July 2013
Offline
1) Take the name string up to the first non-letter character and add them to a list if they are not already in the list. This will give you a list of unique 'starter' strings.

2) sort the list by length, longest ones first. this is to help keeping "part_1234" and "partOther_1234" apart.

3) loop over list items and group them by item*. Make sure to only add to the group if it's not in a group already. This in combination with the sorting will avoid the "part" group from getting the "partOther" items.
Edited by Jonathan de Blok - Dec. 11, 2023 18:37:53
More code, less clicks.
User Avatar
Member
313 posts
Joined: March 2023
Offline
If the text you're trying to match have a similar pattern (like I see on your screenshot) you can use regex which is a powerfull way of detecting text and capturing section.

for exemple :
string match[] = re_find(r"-(.*)\((.*)\)", s@name);

s@group = match[1];
s@data = match[2];

regex interactive :

https://regex101.com/r/EKgQ0H/1 [regex101.com]



then once you splitted your complex text into smaller 'chunk' you can further process them and group them by what you want
Edited by ASquirrel - Dec. 11, 2023 19:44:56

Attachments:
007511_houdini_6Dax6J5hsf_2023-12-12_01-41-31.png (136.3 KB)
example_regex.hiplc (75.7 KB)

Head of Pipeline @ LightVFX
User Avatar
Member
294 posts
Joined: July 2013
Offline
I've tweaked the hip file a bit for more robust output and to create actual groups as well while we're at it.

What it does is takes the first part of the string and uses that as main part name, the other matches are kept as an array of subnames. If you look at the input 'name' attrib values you can see I've made them extra messy yet the 'part_name' and 'part_subnames' values come out quite nicely.






Edited by Jonathan de Blok - Dec. 12, 2023 04:01:11

Attachments:
example_regex_v0002.hiplc (76.8 KB)
Screenshot 2023-12-12 095434.jpg (46.1 KB)
Screenshot 2023-12-12 095452.jpg (98.7 KB)

More code, less clicks.
User Avatar
Member
2 posts
Joined: April 2015
Offline
WHOA! Guys I am sorry for not responding to this. I truly appreciate this help. Thank you so much. Even though it is months late!
  • Quick Links