I don’t think that will get you there… The number of members in a group will not help determine what level of grouping you’re at. I’m not sure what the official definition of “Top group” is or what the logical approach to getting it should be… There are so many scenarios possible. For example, in the image below, which is the top group…?
Exactly. Each groups gets added to the GroupTable. The last group in the GroupTable where object has been “spotted”, is its top group.
import rhinoscriptsyntax as rs
import scriptcontext as sc
id = rs.GetObject()
groupNames = sc.doc.Groups.GroupNames(False)
groupName = False
for i in range(rs.GroupCount()):
groupRO = sc.doc.Groups.GroupMembers(i)
for ele in groupRO:
if rs.coercerhinoobject(ele).Id == id:
groupName = groupNames[i]
print "the element you chose does not belong to any group"
Have you tried it on the red sphere which only belongs to Group01 ? I´ve too compared with below script from the vbscript helpfile which gives different results compared to the python version above:
Dim strObject, strGroup
strObject = Rhino.GetObject("Select object",, True)
If Not IsNull(strObject) Then
strGroup = Rhino.ObjectTopGroup(strObject)
If Not IsNull(strGroup) Then
Rhino.Print "Top object group: " & strGroup
Ok. Btw. In my file there is no deleted group. I´ve just been wondering myself how to do it.
Strangely, my counting members strategy seems to be working
I am organising paths to be sent off for lasercutting. I am looking to collect all the objects in layer and arrange them in a rough ‘nest’. Many of these ‘objects’ are grouped collections of paths, and I want to make sure I move the whole group and an not the sub objects.
grplist = rs.ObjectGroups(obj_id)
biggestGroup = 0
for grp_id in grplist:
memberCount = len(rs.ObjectsByGroup(grp_id))
if memcnt >= biggestGroup:
topGroup = grp_id
biggestGroup = memberCount
This seems to work as I hoped, returning the group name that contains all of the curves that would be selected if you were to click on something in the Rhino window. I can use this to manipulate the whole group and find the bounding box etc.
Perhaps what I am looking for is not the ‘top group’, but this seems to work for me. It allows me to specify a sub-object and get all the other objects that are linked to it in the group, and that is all I need
I realise now this only works for me because of how I model. I don’t ever combine sub-objects from one group with another: I just make larger, all-encompassing groups, which is why this works for me.
In this context, the ‘top group’ is easy to calculate.