Delete unused groups - please help

Hi everyone.

I am struggling with something and I hoped someone here could help.

I have a program that takes requests (in the form of car areas like "front wing") and makes groups for them in a hierarchy and then queries a server for data for the areas and makes splines (CFD streamlines). However, as a CFD run might not have data for all the areas requested, some groups can be left empty which I don't like.

I need a way to find all of the empty groups so that I can delete them before the program finishes. I can't just make a list of groups I used and delete the others because the user could use the button twice to get different car areas and I don't want the second attempt deleting the stuff from the first. Also I prefer to make the groups at the start rather than after successfully getting data back from the server because it is easier to do the hierarchy.

Can anyone think of a way to help me go through my groups and delete ones with nothing in them (other than another group (which could be done with a dictionary of groups to parent groups))

Thanks

Nick

The code below will report the groups in the current work part, the number of objects each group contains, and any groups that contain the given group. This code could be adapted to find and delete empty groups.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work

Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim tmpGrp As NXOpen.Tag = NXOpen.Tag.Null
Dim myGroup As Group

Dim numMembers As Integer
Dim memberTags() As Tag

Dim numOwningGroups As Integer
Dim owningGroups() As Tag

Do
theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_group_type, tmpGrp)
'skip the initial null tag
If tmpGrp = NXOpen.Tag.Null Then
Continue Do
End If

myGroup = Utilities.NXObjectManager.Get(tmpGrp)
lw.WriteLine("group name: " & myGroup.Name)

theUfSession.Group.AskGroupData(myGroup.Tag, memberTags, numMembers)
lw.WriteLine(" group contains: " & numMembers.ToString & " members")

theUfSession.Group.AskAllOwningGroups(myGroup.Tag, numOwningGroups, owningGroups)
If numOwningGroups > 0 Then
lw.WriteLine(" owned by: " & numOwningGroups.ToString & " other group(s)")
End If

lw.WriteLine("")
Loop Until tmpGrp = NXOpen.Tag.Null

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Thanks a bunch! I will give it a go and if I get it working I will post the working code for others who look in the future