Simple script request

Imagine the pile of data which is a set of groups within a groups and the it is grouped at the end :slight_smile: resulting a read of basillion instances (without hierarchy) in a group panel, and I’m talking about hundreds.
Is it possible to script an action that removes all subgroups living the last ones? Not sure if I explained it well, if not, I will try harder.

You might try the following…

Option Explicit
Call RemoveNestedGroups()
Sub RemoveNestedGroups()
	Dim arrObjs,strObj,arrObjGroups,strTG,strGroup,arrGroups
	arrObjs = Rhino.GetObjects("Select objects to process")
	If Not IsArray(arrObjs) Then Exit Sub
	For Each strObj In arrObjs
		arrObjGroups = Rhino.ObjectGroups(strObj)
		If IsArray(arrObjGroups) Then
			strTG = Rhino.ObjectTopGroup(strObj)
			For Each strGroup In arrObjGroups
				If strGroup <> strTG Then
					Call Rhino.RemoveObjectFromGroup(strObj, strGroup)
				End If
			Next	
		End If	
	Next
	arrGroups = Rhino.GroupNames()
	If isArray(arrGroups) Then
		For Each strGroup In arrGroups
			If Rhino.IsGroupEmpty(strGroup) Then
				Rhino.DeleteGroup(strGroup)
			End If
		Next	
	End If
End Sub

Note, it is difficult to know with nested groups which is the objects uppermost group. Rhinoscript has a method ObjectTopGroup() which theoretically finds this, but I’m not sure it’s 100% reliable. The method is not currently exposed in Python, hence the VB script. Try the script out on some copies of files first.

The above in an .rvb file
RemoveNestedGroups.rvb (750 Bytes)

–Mitch

2 Likes

Hi Mitch
You never fail to amaze me. if I only knew how to apply this alien language into my workflow…
Can it be converted to rvb? I understand that PY is not possible in this case.
Many thanks for your effort.
P

I threw it in in my post above. Note, I haven’t tested it at all, so let me know how (and if) it works…

Mitch
It works like a charm.
I did a quick test. It went from hundreds to hundred groups. I have later isolated selected groups to check if anything nested is left and the result was: none. Congratulations.
I would like to offer you a beer or two next time I see you in STF in London :slight_smile:

Definitely !! :beers: