Group for objects having the same name obj

python
unhandled

(Pie Ventura) #1

sorry,

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

help me


#2

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

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

(Pie Ventura) #3

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


(Pie Ventura) #4

tnx but i dont understand where im broken the step


(Pie Ventura) #5

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)


#6

OK, I thought that was what you wanted…

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


(Pie Ventura) #7

i love you
:slight_smile:


#8

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


(Pie Ventura) #9

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.


(Willem Derks) #10

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


#11

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


(Pie Ventura) #12

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

Uploading…