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: sc.doc.ActiveDoc.Groups.IsDeleted(sc.doc.ActiveDoc.Groups.Find(group.Name))
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
@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:
for group in scriptcontext.doc.Groups:
rc = scriptcontext.doc.Groups.FindId(group.Id)
but it does list the deleted groups too. Btw. FindId is missing in the RhinoCommon docs ?!
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
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)
print "Deleted Name:", group.DeletedName
print "Name:", group.Name
@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
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?