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

User Selection of Groups to TaggedObject array

[ Edited ]

Hello,

 

I am looking to ask the user to select one or more existing Groups, and getting a list of Groups I can use from it (From my research I assume this will be an array of TaggedObject, which is fine). I was curious if there was an NX capability to pull up some sort of dialog box to do this. If not, should I be using the custom UI Block Styler?

 

I would post code, but I do not know what object to start with. Considered:

NXOpen.Selection.SelectTaggedObjects()

Hoping someone can explain how this could be used to solve my problem, or give an alternate object that would be better suited. 

1 REPLY
Solution
Solution
Accepted by topic author Ryan_
‎06-09-2017 12:36 PM

Re: User Selection of Groups to TaggedObject array

Try this:

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()

    Dim theUI As UI = UI.GetUI()
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ")

        lw.Open()

        Dim selGroups As New List(Of Group)

        If SelectGroups("select groups", selGroups) = Selection.Response.Cancel Then
            Return
        End If

        lw.WriteLine("number of groups selected: " & selGroups.Count.ToString)
        For Each temp As Group In selGroups
            lw.WriteLine("group name: " & temp.Name)
            lw.WriteLine("group tag: " & temp.Tag.ToString)
            lw.WriteLine("")
        Next

        lw.Close()

    End Sub


    Function SelectGroups(ByVal prompt As String, ByRef selGroups As List(Of Group)) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select groups"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple
        Dim selObj() As TaggedObject

        With selectionMask_array(0)
            .Type = UFConstants.UF_group_type
            .Subtype = 0
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt,
        title, scope, selAction,
        includeFeatures, keepHighlighted, selectionMask_array,
        selObj)
        If resp = Selection.Response.Ok Then
            For Each temp As NXObject In selObj
                If TypeOf (temp) Is NXOpen.Group Then
                    selGroups.Add(temp)
                End If
            Next
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    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