How to check if a group has been deleted?

I’m using sc.doc.ActiveDoc.Groups to get the group table.

then I want to check if the user has deleted a group, but:

will not mark the groups as deleted, unless I purge the groups.

Is there another way to do this?

Eventually my goal is to add numbered groups to the document, but if the user deletes or undo the operation, I want this to affect my counter. So the idea is to get the list of groups and check the numbers if there is a free ‘slot’. For example: if user adds 3 groups and deletes nr. 2, the next number should 2 instead of 4

Hi @Gijs, for the moment you might check the groups object count eg:

if scriptcontext.doc.Groups.GroupObjectCount(group_index) == 0:
    is_deleted = True
    is_deleted = False

@dale, imho this should be flagged as a bug which has been in Rhino 5 as well, IsDeleted should work. Since working with indices is discouraged i tried to iterate the grouptable and use FindId instead:

import scriptcontext

def DoSomething():
    for group in scriptcontext.doc.Groups:
        rc = scriptcontext.doc.Groups.FindId(group.Id)
        print rc

but it does list the deleted groups too. Btw. FindId is missing in the RhinoCommon docs ?!


Thanks @clement I will check that out.

Since this is buggy I might better use something else to check this, maybe simply the ID of one of the objects? Or could I for example attach user data to all objects in the group and check how many objects there are with the same key/value pair?

I found something else that’s buggy:
When I delete the group, purge it, then undo the purge and delete, I will get the group back, but in the script they remain flagged as deleted.

edit: also when deleting a group, then purging, then clearUndo, I can still retrieve the group.Id

This seems to work:

import Rhino
import scriptcontext as sc

if sc.doc.Groups.Count > 0:
    for index in range(sc.doc.Groups.Count):
        group = sc.doc.Groups.FindIndex(index)
        rc = sc.doc.Groups.IsDeleted(index)
        if rc:
            print "Deleted Name:", group.DeletedName
            print "Name:", group.Name

What am I missing?

– Dale

I think, if the group has been deleted, the group.Name will be None and the group.DeletedName will be the old group.Name (at least that is what I am observing here). So:


Isn’t giving you a valid index for


Which seems to always return False with an invalid index.

– Dale

Edit: ah now I see after rereading
Will check this out thanks @dale @nathancoatney

@dale: what makes this fail: If a user manually deletes a group of objects, the objects are deleted, but the group isn’t UNTIL the group is purged with Purge command. I guess it is designed this way so can’t rely on group names and have to look at the objects that were in the group instead.

note for others and myself: renaming a group will change its index and the old name becomes a deleted group

Hi @dale, i usually search on the left dropdown where it is still missing:

btw. the description text of FindName and FindNameHash need some love.

do you mean in python editor? I do have FindId listed there (rhino 6.14)

indeed, noticed that too. Would be great if we could add additional notes / suggestions for corrections / sample scripts to these pages

No i mean the online help here.


@clement - from the center section:

– Dale

How does a user do this? If they just pick a group of objects and press Delete, then the objects are deleted but the group is not…

– Dale

Exactly but it took me some tries to find that out. It’s a bit counterintuitive at least, because in Rhino you cannot select a group that has no objects. If I want to select groups by name, empty groups will not appear in the list. So it’s more a matter of confusion caused by the fact that in script context empty groups still remain alive.
So basically it means I have to look for groups that are not deleted AND are empty, right?

Hi @dale, i see this but could the menu be updated as well ?


No idea - but I’ve created an issue for this.

– Dale

1 Like