Group for objects having the same name obj

sorry,

i want make a group for objects having the same name obj
one group/ one obj (with the same name obj)

help me

How about just adding this to your code inside your loop - after rs.SetUserText()…

group=rs.AddGroup(name+str(suffix))
rs.AddObjectsToGroup(item,group)

autolabel group.py (2.8 KB)
4_try count group by obj name.3dm (637.3 KB)

tnx but i dont understand where im broken the step

sorry i’m a beginner
@Helvetosaur tnx
your code is ok but dont make a group whit more of one obj whit the same name obj
tnx infinitely

autolabel group.py (2.8 KB)
new try count group by more obj name.3dm (167.4 KB)

OK, I thought that was what you wanted…

I’ll have a look later if I have time…

i love you
:slight_smile:

Bbbbuut… you don’t even know me…! :stuck_out_tongue_winking_eye:

Let me see if I can clarify your need here - you have a series of objects which have object names, and some of the objects have the same name as other objects… You would like to create as many groups as there unique object names, and have all the same-named objects go into the same group - which has the same name as the object(s).

Did I get that right?

–Mitch

1 Like

exactly,
all objects with the same name are in the same group.
each set of objects with the same name creates a group.
many sets, many groups.
Thank you very much.

Not sure how to interpret your script, but a solution to the description might be this:

import rhinoscriptsyntax as rs

def grouped_by_name():
    objs = rs.GetObjects()
    if not objs: return
    
    #collect names of all objects
    all_names = [rs.ObjectName(obj) for obj in objs]
    #reate a list from a set, the set will contain only unique items
    unique_names = list(set(all_names))
    #cull a possible None value for objects that had no name
    true_names = [name for name in unique_names if not name == None]
    
    for group_name in true_names:
        rs.AddGroup(group_name)
        named_objects = [obj for obj in objs if rs.ObjectName(obj) == group_name]
        rs.AddObjectsToGroup(named_objects, group_name)
    
 
if __name__=="__main__":
    grouped_by_name()

-Willem

2 Likes

Thanks Willem, that’s pretty much what I was going to suggest, just stuck here running lasers this afternoon, not much time.

2 Likes

cazzo fortissimo,tnx
you are great @Willem and @Helvetosaur.
is perfect for me
molte grazie
ciao

Uploading…