Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

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

Next

 

 

 

Sina shojaee
1 REPLY
Solution
Solution
Accepted by topic author sina
‎09-12-2015 12:29 AM

Re: Cycle through Groups

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
        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)")
                'theUfSession.UF.Free(owningGroups)
            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