hexagon logo

Has anyone made a script to list all used probes (tips) in all programs?

Has anyone made a script to list all used probes (tips) in all programs (in a certain folder)? Technically it should be possible - get a list of all programs, open them one after another, scan for LOADPROBE and TIP commands, collect data.

But has anyone already done it? And is able to share?
Parents
  • I have a vb.net program that lists all the probes in an open program. Then you can select on the form whether to view all probes/angles, or only unique probes/angles. I stripped some of the code out to see if you can adapt it. You'll need to write the section to iterate through the files. Side note: I export a copy of the text for every program when it is ran. Then I can scan through the text files very quickly for anything specific instead of opening and closing hundreds of programs.

    You'll want to change the "write out results" section at the end to fit your needs.

    See if this helps any:
    Imports System.Text
    
    Module Module1
        Sub FindAll()
            Dim Pcd_app As PCDLRN.Application = New PCDLRN.Application
            Dim lstProbesAngles As New List(Of String)
            Dim strUniqueProbes As New StringBuilder
            Dim strAllProbes As New StringBuilder
            Dim ds As New DataSet
            Dim count As Integer = 0
            Dim sProbe As String
            Dim sAngle As String
            Dim bDupe As Boolean = False
            Dim strProgramText As String = Pcd_app.ActivePartProgram.EditWindowTextAll 'get program text
            Dim splCMDs() As String = Split(strProgramText, Chr(10)) 'split text lines into array
    
            strAllProbes.AppendLine("Tip/Angle".PadRight(24) & "Line#")
            strAllProbes.AppendLine("-".PadRight(30, "-"))
    
            strUniqueProbes.AppendLine("Tip/Angle".PadRight(24) & "Line#")
            strUniqueProbes.AppendLine("-".PadRight(30, "-"))
    
            For Each s In splCMDs 'iterate through each line
                Dim str As String = ""
                count += 1
                If s.Contains("LOADPROBE") Then 'if new probe
                    Dim spl() As String = s.Split("/")
                    sProbe = spl(1).Trim
                    'create new table for probe if it doesn't already exist
                    If Not ds.Tables.Contains(sProbe) Then
                        ds.Tables.Add(sProbe)
                        With ds.Tables(sProbe)
                            .Columns.Add("Angle")
                            .Columns.Add("Line")
                            Dim keyColumn(1) As DataColumn
                            keyColumn(0) = .Columns(0)
                            ds.Tables(sProbe).PrimaryKey = keyColumn
                        End With
                        strAllProbes.AppendLine(sProbe.PadRight(24) & count) 'add to full probe list
                    Else
                        strAllProbes.AppendLine("*" & sProbe.PadRight(23) & count) 'add to full probe list with * to indicate duplicate
                    End If
                ElseIf s.Contains("TIP/") Then 'probe angle
                    Dim spl() As String = s.Split("/")
                    sAngle = Strings.Left(spl(1).Trim, InStr(spl(1).Trim, ",") - 1) 'get tip name
                    'try to add to table, if error returned, then tip is already in table.
                    Try
                        ds.Tables(sProbe).Rows.Add({sAngle, count})
                    Catch ex As Exception
                        Console.WriteLine(sProbe & " - " & ex.Message)
                        bDupe = True
                    End Try
                    'if duplicate tip, add to list with * 
                    If bDupe Then
                        strAllProbes.AppendLine("   *" & sAngle.PadRight(20) & count)
                        bDupe = False
                    Else
                        strAllProbes.AppendLine("    " & sAngle.PadRight(20) & count)
                    End If
    
                End If
            Next
    
            'convert table to string builder object
            For Each t As DataTable In ds.Tables
                t.DefaultView.Sort = "Angle" & " DESC"
                strUniqueProbes.AppendLine(t.TableName)
                For Each r As DataRow In t.Rows
                    strUniqueProbes.AppendLine("    " & r(0).ToString.PadRight(20) & r(1))
                Next
            Next
    
            'write out results
            Console.WriteLine("--Unique Probes--")
            Console.WriteLine(strUniqueProbes.ToString)
            Console.WriteLine("")
            Console.WriteLine("")
            Console.WriteLine("--All Probes--")
            Console.WriteLine(strAllProbes.ToString)
    
            Pcd_app = Nothing
        End Sub
    End Module
Reply
  • I have a vb.net program that lists all the probes in an open program. Then you can select on the form whether to view all probes/angles, or only unique probes/angles. I stripped some of the code out to see if you can adapt it. You'll need to write the section to iterate through the files. Side note: I export a copy of the text for every program when it is ran. Then I can scan through the text files very quickly for anything specific instead of opening and closing hundreds of programs.

    You'll want to change the "write out results" section at the end to fit your needs.

    See if this helps any:
    Imports System.Text
    
    Module Module1
        Sub FindAll()
            Dim Pcd_app As PCDLRN.Application = New PCDLRN.Application
            Dim lstProbesAngles As New List(Of String)
            Dim strUniqueProbes As New StringBuilder
            Dim strAllProbes As New StringBuilder
            Dim ds As New DataSet
            Dim count As Integer = 0
            Dim sProbe As String
            Dim sAngle As String
            Dim bDupe As Boolean = False
            Dim strProgramText As String = Pcd_app.ActivePartProgram.EditWindowTextAll 'get program text
            Dim splCMDs() As String = Split(strProgramText, Chr(10)) 'split text lines into array
    
            strAllProbes.AppendLine("Tip/Angle".PadRight(24) & "Line#")
            strAllProbes.AppendLine("-".PadRight(30, "-"))
    
            strUniqueProbes.AppendLine("Tip/Angle".PadRight(24) & "Line#")
            strUniqueProbes.AppendLine("-".PadRight(30, "-"))
    
            For Each s In splCMDs 'iterate through each line
                Dim str As String = ""
                count += 1
                If s.Contains("LOADPROBE") Then 'if new probe
                    Dim spl() As String = s.Split("/")
                    sProbe = spl(1).Trim
                    'create new table for probe if it doesn't already exist
                    If Not ds.Tables.Contains(sProbe) Then
                        ds.Tables.Add(sProbe)
                        With ds.Tables(sProbe)
                            .Columns.Add("Angle")
                            .Columns.Add("Line")
                            Dim keyColumn(1) As DataColumn
                            keyColumn(0) = .Columns(0)
                            ds.Tables(sProbe).PrimaryKey = keyColumn
                        End With
                        strAllProbes.AppendLine(sProbe.PadRight(24) & count) 'add to full probe list
                    Else
                        strAllProbes.AppendLine("*" & sProbe.PadRight(23) & count) 'add to full probe list with * to indicate duplicate
                    End If
                ElseIf s.Contains("TIP/") Then 'probe angle
                    Dim spl() As String = s.Split("/")
                    sAngle = Strings.Left(spl(1).Trim, InStr(spl(1).Trim, ",") - 1) 'get tip name
                    'try to add to table, if error returned, then tip is already in table.
                    Try
                        ds.Tables(sProbe).Rows.Add({sAngle, count})
                    Catch ex As Exception
                        Console.WriteLine(sProbe & " - " & ex.Message)
                        bDupe = True
                    End Try
                    'if duplicate tip, add to list with * 
                    If bDupe Then
                        strAllProbes.AppendLine("   *" & sAngle.PadRight(20) & count)
                        bDupe = False
                    Else
                        strAllProbes.AppendLine("    " & sAngle.PadRight(20) & count)
                    End If
    
                End If
            Next
    
            'convert table to string builder object
            For Each t As DataTable In ds.Tables
                t.DefaultView.Sort = "Angle" & " DESC"
                strUniqueProbes.AppendLine(t.TableName)
                For Each r As DataRow In t.Rows
                    strUniqueProbes.AppendLine("    " & r(0).ToString.PadRight(20) & r(1))
                Next
            Next
    
            'write out results
            Console.WriteLine("--Unique Probes--")
            Console.WriteLine(strUniqueProbes.ToString)
            Console.WriteLine("")
            Console.WriteLine("")
            Console.WriteLine("--All Probes--")
            Console.WriteLine(strAllProbes.ToString)
    
            Pcd_app = Nothing
        End Sub
    End Module
Children
No Data