Showing results for 
Search instead for 
Did you mean: 

Cycle through Groups


I want to write a VB Program in Drafting application to cycle through all groups and do something on them but I don't know the exact hierarchy of groups in workpart:



Dim Group As Group

For each Group In '......'

'Do something





Sina shojaee

Re: Cycle through Groups

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Here's one way to cycle through groups in a part:


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

        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

            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

        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