Delete & groups

Hi all!
How can I delete objects from groups?
How can I ungroup objects in groups?
What is the best way to delete groups (hopefully with undo support)
Thanks to you all.


Hi @software_comas,

If you find the group index from a single group name, you could access the object properties and remove the object from one group like this


To remove it from any group, use rh_obj.Attributes.RemoveFromAllGroups()

The fastest way is to delete the group using it’s index. I guess it works with undo.


1 Like

Actually, it doesn’t work with undo.
Anyway, thanks again for your replies! :slight_smile:

@software_comas, i am not sure how to handle the undo in C# but in Python i add CustomUndoEvent in which i can store the group index i have deleted. Then if the operation is undone, i use GroupTable.Undelete(e.Tag) to get the group back. e.Tag is the index of the deleted group which i stored in the event.


Undo is handled basically in the same way, in C#.
I have found some information you may find useful, here.
I have choosen not to delete groups but just delete all the grouped objects.
You may say I get a a lot of empty groups in the document but, as you can read in the link above, empty groups are automatically deleted on document load/save and, in addiction, you don’t have to manage groups in your custom undo event.
Hope this is useful, somehow…

OK, that was not clear to me as you wrote “the best way to delete groups”. I guess you could just delete the objs and do not have to take care about their groups.

No, in all my scripts dealing with groups i use IsDeleted before i do something. So this is not a problem.

You helped me a lot!
thanks again! :slight_smile: