' =============================================================================
' NX Journal: probe SelectionBlock / ScCollector API (NX 2506)
'
' Purpose: StepCreator has an ExportSelectionBlock property. If batch mode has
'   no "DisplayPart", we may be able to export by EXPLICITLY selecting the
'   bodies into the ExportSelectionBlock. This probe dumps the exact API so the
'   next script can use it correctly (compile-safe).
'
' Dumps:
'   1. Type of StepCreator.ExportSelectionBlock
'   2. Members of that type
'   3. Members of NXOpen.SelectionBlock, NXOpen.ScCollector (if found)
'   4. All types whose name contains "Selection" or "Collector"
'
' Run: WorkingDirectory = catalog-masters\KC; run_journal.exe <this file>
' Result: <cwd>\probe-selection.txt
'
' Note: English comments only (avoids GBK/BOM mojibake on no-BOM .vb files).
' =============================================================================
Option Strict Off
Imports System
Imports System.IO
Imports System.Text
Imports NXOpen
Imports NXOpen.UF

Module ProbeSelection

    Function FindType(n As String) As System.Type
        Dim t As System.Type = GetType(Session).Assembly.GetType(n, False)
        If t IsNot Nothing Then Return t
        For Each a As System.Reflection.Assembly In AppDomain.CurrentDomain.GetAssemblies()
            t = a.GetType(n, False)
            If t IsNot Nothing Then Return t
        Next
        Return Nothing
    End Function

    Sub DumpMembers(sb As StringBuilder, prefix As String, t As System.Type)
        If t Is Nothing Then
            sb.AppendLine(prefix & " [NULL]")
            Return
        End If
        sb.AppendLine("=== " & t.FullName & " ===")
        For Each mi As System.Reflection.MemberInfo In t.GetMembers()
            If mi.MemberType = System.Reflection.MemberTypes.Method OrElse
               mi.MemberType = System.Reflection.MemberTypes.Property Then
                sb.AppendLine(prefix & ": " & mi.MemberType & " " & mi.Name)
            End If
        Next
    End Sub

    Sub Main()
        Dim sb As New StringBuilder()

        ' 1. Type of StepCreator.ExportSelectionBlock
        Dim scT As System.Type = GetType(NXOpen.StepCreator)
        Dim esb As System.Reflection.PropertyInfo = scT.GetProperty("ExportSelectionBlock")
        If esb IsNot Nothing Then
            sb.AppendLine("StepCreator.ExportSelectionBlock type = " & esb.PropertyType.FullName)
            DumpMembers(sb, "ESB", esb.PropertyType)
        Else
            sb.AppendLine("StepCreator.ExportSelectionBlock NOT FOUND")
        End If

        ' 2. SelectionBlock / ScCollector
        DumpMembers(sb, "SELB", FindType("NXOpen.SelectionBlock"))
        DumpMembers(sb, "SCCO", FindType("NXOpen.ScCollector"))
        DumpMembers(sb, "SEL", FindType("NXOpen.Selection"))

        ' 3. All types containing Selection / Collector
        sb.AppendLine("=== types containing Selection/Collector ===")
        For Each t As System.Type In GetType(Session).Assembly.GetTypes()
            Dim n As String = t.FullName
            If n.IndexOf("Selection", StringComparison.OrdinalIgnoreCase) >= 0 OrElse
               n.IndexOf("Collector", StringComparison.OrdinalIgnoreCase) >= 0 Then
                sb.AppendLine("T: " & n)
            End If
        Next

        File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "probe-selection.txt"), sb.ToString(), New UTF8Encoding(True))
    End Sub

End Module
