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

@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.