Select Component and keep it selected for the User

Hello,



I have created a journal that finds a specific component in an assembly by it's attribute's value.

Now I would like to have this component selected (not just highlighted...) to pass this selection to the user.

My code (which is not yet cleaned up - sorry.) actually looks like this:

' Find_Component_by_NAME.vb
' This program walks an assembly structure starting from the WorkPart.
' For each component below the Work Part it will
' look for the component Attribute "NAME" to be set to a certain value
' Based on a script from NXJOURNALING.COM

Option Strict On
Imports System
Imports System.IO
Imports System.Collections

Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.Drawings
Imports NXOpen.UF '.Net wrapped User Function

Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim ufSession As UFSession = ufSession.GetUFSession()
Dim LW As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work
Dim alreadyProcessed As Hashtable
Dim prototype As Part
Dim knt As Integer = 0
Dim AttribValue As String
Dim SearchString As String = "XYZ"

Sub Main()
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Replace Reference Set to Entire Part")

LW.Open()

Try

Dim part1 As Part = theSession.Parts.Work
Dim origPart As Part = part1

' Initialize a hash table to store components that have been processed.
' This will prevent components from being processed twice
alreadyProcessed = New Hashtable

Dim c As ComponentAssembly = part1.ComponentAssembly

Walk(c.RootComponent, 0)

Catch e As Exception
'LW.WriteLine("Error running application: " & e.Message)
End Try
End Sub

Sub Walk(ByVal c As Component, ByVal level As Integer)

Dim children As Component() = c.GetChildren()
Dim child As Component
prototype = CType(c.Prototype, Part)

If Not alreadyProcessed.Contains(prototype) Then
' Add this prototype to the hash table so that we don't process it again
alreadyProcessed.Add(prototype, prototype)
knt = knt + 1
End If

For Each child In children
Try
AttribValue=child.GetStringAttribute("NAME")
If AttribValue = SearchString Then
child.Highlight()
child.UnHighlight()
'child.Blank()
End If
Catch ex As NXException
'512008 = attribute not found
If ex.ErrorCode = 512008 Then
'component is in list but does not have the attribute, create attribute and set to value in list
'myComp.SetAttribute(attributeTitle, previousValue)
lw.WriteLine("## Error: " & ex.ErrorCode & " : " & ex.ToString)
Else
'some other error occurred
lw.WriteLine("## Error: " & ex.ErrorCode & " : " & ex.ToString)
End If
End Try
'recurse
Walk(child, level + 1)
Next
End Sub
End Module

As you can see, I've experimented with "Highlight" but that's not doing the job: I need to have the component selected when the programme terminates. And it would be nice to have it expanded in the ANT which I think should be possible once I have it selected.

Any Suggestions?

btw: Where is the search function in this forum?

Thank you very much!

I don't think modifying the selection is available for use in "plain vanilla" journals. There is an existing enhancement request (ER) for this functionality to be added (ER 1785948). Contact GTAC and have them add you to the ER list; as more people request it, the more weight it will be given for inclusion in a future release.

That said, if you'd like to present the user with a selection dialog box with some objects pre-selected, which would allow the user to select/deselect objects for further processing within your journal; that much is possible. An example of this approach can be seen in:
http://nxjournaling.com/content/show-reference-set-objects