Is there a way to accesss groups-information in an object?

I wanna get a group_id of grouped objects to use it as an identifier. In python, do you know how I get this information?

Rhino groups or Grasshopper transform groups or Grasshopper UI groups?

Rhino groups.

I wanna sort objects according to its group_name that contains.

@okay8282,

in Rhino objects can be grouped multiple times and be part of nested groups, so each object can have multiple group names it belongs to. Below sorts a list of object ids by their first group name. If an object is not part of a group, it is listed at the beginning:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    ids = rs.GetObjects("Select grouped objects", 0, True, False)
    if not ids: return
    
    def SortFunc(id):
        group_names = rs.ObjectGroups(id)
        if not group_names: return ""
        else: return group_names[0]
    
    ids.sort(key=SortFunc, reverse=False)
    
    for id in ids:
        group_names = rs.ObjectGroups(id)
        if not group_names: gn = ""
        else: gn = group_names[0]
            
        print "ObjectId: {}  GroupName: {}".format(id, gn)
    
DoSomething()

_
c.

Thank you so much :wink:

Hello,
i have the same group name problem, but I don’t know how to work with this python script, thanks for your help.

@Philippe_HAMON,

the script alphabethically sorts a list of grouped objects by their group name and then prints out the object ids and groupnames. What are you trying to do ?

_
c.

I’m only trying to retrieve the group name of multiple objects, but I don’t know how to input this script in grasshopper (I don’t know anything in programming)

I insert manually several dxf files in Rhino (for layer based cnc cutting informations, a sort of post-processor), each file is inserted as a group named with the original file name. I found a VB script that retrieved the file names, but they are alphabetically sorted, and don’t match the data’s order. I need a non sorted list of group names. I tried to paste your script in a python script component, but I think it’s not so easy…

Hi @Philippe_HAMON,

have you tried Human PlugIn and seen this ?

_
c.

Yes, but the objects aren’t in the group order:

The better way would be to retrieve the group name of each object in the green panel, it’s what I’m enable to do. Thanks for your help.

@Philippe_HAMON,

i see now, you’re using the geometry pipeline so i asume the object order is just the order of the object table in rhino. One thing which makes me unsure if it would help to receive one data tree per group name, are all objects in a single group ? (In Rhino an object can belong to multiple groups).

_
c.

Hello
Yes, one object is only in one group. If I could acces to the group information in an object, I think I could remap a group tree, or in an other way, maybe keep the group’s rhino order.

Hi @Philippe_HAMON,

i can only provide this example under reservation as i think i found a small bug in GH (Rhino 6).

There are two components, one lists the group name for each object and the other (which has no inputs but two outputs) gives the group name(s) and the objects in the group. To make this refresh i connected a timer, otherwise just press F5 and it updates. Both components are not tested extensively so please try it first in a simple example, especially try what happens when you delete a group by ungrouping.

ObjectsAndGroups.gh (8.8 KB)
ObjectsAndGroups.3dm (31.6 KB)

_
c.

Thank you very much Clement, it looks to work, but the two components doesn’t sort the group the same way…
I come back to you, I have to verify which one has got the right order, thank you again!

It’s OK with this one, the group order is fine:

Merci beaucoup Clément (Français?)

@Philippe_HAMON, germany at this time.

thanks for letting me know. Take care with deleted groups and that second component. I’ve found that _Purge _Groups=Yes helped sometimes to get rid of them.
_
c.

Yes, I already did purge the file before each import.
Thank you for your help!