hexagon logo

Tracefields and Scripts

Anyone out there know how to retrieve a Tracefield Value from a part program in a script? Can't quite find the right command...
Parents
  • OK here is what I made from your example -
    Sub Main()
    
    'Declares PC-DMIS As the Active Program/Application
    Dim PCDApp As Object
    Dim Part As Object
    Dim Cmds  As Object
    Dim Cmd As Object
    Dim TCmd As Object
    Dim TCmds As Object
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set Part = PCDApp.ActivePartProgram
    Set Cmds = Part.Commands
    Dim VSERIALNUMBER As String
    
        For Each Cmd In Cmds
              If Cmd.IsTraceField Then
      
              If Cmd.GetText(TRACE_NAME, 0) = "Serial Number" Then
                    VSERIALNUMBER = Cmd.GetText(TRACE_VALUE, 0)
                    MsgBox VSERIALNUMBER
              End If
    
     End If
    
    Next Cmd
    
    
    End Sub


    and these are the changes I made, to get it working

    I removed the ObjFSO references, don't hurt, but not needed

    I changed the Dim VSERIALNUMBER As String, was formerly an object declaration

    I removed the command reference, which was formerly "Set TCmd = Cmd.TraceFieldCommand", just wasn't needed

    Once we find the TraceField command we can test for the name and value with the following -

    If Cmd.GetText(TRACE_NAME, 0) = "Serial Number" Then
    VSERIALNUMBER = Cmd.GetText(TRACE_VALUE, 0)
    MsgBox VSERIALNUMBER
    End If

    I added the Msgbox in there to display what it was capturing, for my own checking. Check it out, let me know if it works for you.

    We can also remove the TCmd declarations, as they are not necessary in my example

    Dim TCmd As Object
    Dim TCmds As Object
Reply
  • OK here is what I made from your example -
    Sub Main()
    
    'Declares PC-DMIS As the Active Program/Application
    Dim PCDApp As Object
    Dim Part As Object
    Dim Cmds  As Object
    Dim Cmd As Object
    Dim TCmd As Object
    Dim TCmds As Object
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set Part = PCDApp.ActivePartProgram
    Set Cmds = Part.Commands
    Dim VSERIALNUMBER As String
    
        For Each Cmd In Cmds
              If Cmd.IsTraceField Then
      
              If Cmd.GetText(TRACE_NAME, 0) = "Serial Number" Then
                    VSERIALNUMBER = Cmd.GetText(TRACE_VALUE, 0)
                    MsgBox VSERIALNUMBER
              End If
    
     End If
    
    Next Cmd
    
    
    End Sub


    and these are the changes I made, to get it working

    I removed the ObjFSO references, don't hurt, but not needed

    I changed the Dim VSERIALNUMBER As String, was formerly an object declaration

    I removed the command reference, which was formerly "Set TCmd = Cmd.TraceFieldCommand", just wasn't needed

    Once we find the TraceField command we can test for the name and value with the following -

    If Cmd.GetText(TRACE_NAME, 0) = "Serial Number" Then
    VSERIALNUMBER = Cmd.GetText(TRACE_VALUE, 0)
    MsgBox VSERIALNUMBER
    End If

    I added the Msgbox in there to display what it was capturing, for my own checking. Check it out, let me know if it works for you.

    We can also remove the TCmd declarations, as they are not necessary in my example

    Dim TCmd As Object
    Dim TCmds As Object
Children
No Data