Purge empty groups?

Is there any way to quickly purge all empty groups using python?
I see PurgeLayer(layer) but not seeing something like that for groups?
If there is, does it run on the whole scene and find empty groups? Or do you have to somehow find all the empty groups and get their names?

Hi @mikhail,

You can always just script the Purge command.

– Dale

@dale Do you mean to trigger the purge command from the script?
Something I am doing might create a couple of empty groups here and there. And I wanted to add something at the end of the script to just delete any empty groups after it’s done running.
I don’t want to have the command line to come up with a purge command…
Not sure if something like that exists already…

Thanks!

import rhinoscriptsyntax as rs

cmd = "_-Purge"
cmd += " _BlockDefinitions=_No"
cmd += " _AnnotationStyles=_No"
cmd += " _Groups=_Yes"
cmd += " _HatchPatterns=_No"
cmd += " _Layers=_No"
cmd += " _Linetypes=_No"
cmd += " _Materials=_No"
cmd += " _Enter"

rs.Command(cmd, False)

– Dale

1 Like

@dale Thank you very much!

IsGroupEmpty > DeleteGroup?

Yes, this should also purge empty groups without having to call the Rhino command “Purge”

groups=rs.GroupNames()
for group in groups:
    if rs.IsGroupEmpty(group): rs.DeleteGroup(group)
1 Like

@Helvetosaur Thank you!