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...
  • This is a VB6 example that I have tested -

    Private Sub Form_Load()

    Dim App As PCDLRN.Application
    Dim Part As PCDLRN.PartProgram
    Dim Cmds As PCDLRN.Commands
    Dim Cmd As PCDLRN.Command

    Set App = CreateObject("PCDLRN.Application")
    Set Part = App.ActivePartProgram
    Set Cmds = Part.Commands
    CmdCnt = Cmds.Count

    For Each Cmd In Cmds
    If Cmd.TypeDescription = "Trace Field" Then
    MsgBox Str(Cmd.Type)
    MsgBox Cmd.GetText(TRACE_NAME, 0)
    MsgBox Cmd.GetText(TRACE_VALUE, 0)
    End If
    Next Cmd

    End

    End Sub
  • this works for me using Pcdmis Basic Scripting version 2013:

    Dim DmisApp As Object
    Dim DmisPart As Object
    Dim Commands As Object
    Dim Command As Object
    Dim TraceCommand As Object
    
    Sub Main
    
      Set DmisApp = CreateObject("PCDLRN.Application")
      Set DmisPart = DmisApp.ActivePartProgram
      Set Commands = DmisPart.Commands
    
      For Each Command In Commands 
       If Command.IsTraceField Then
          Set TraceCommand = Command.TraceFieldCommand
          MsgBox TraceCommand.Name + " " + TraceCommand.Value
          Set TraceCommand = Nothing
       End If
      Next Command 
    
    Set Commands = Nothing
    Set DmisPart = Nothing
    Set DmisApp = Nothing
      
    End Sub
  • Thanks for the replies so far guys. I really appreciate it. Just can't quite get what I'm looking for though. I need to be able to take the value from the "Serial Number" tracefield and create a folder with the Trace field value as it's name. I just can't find quite the right commands to do that.

    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 Object
    
    For Each Cmd In Cmds
       
       Set TCmd = Cmd.TraceFieldCommand
    
    Set VSERIALNUMBER = TCmd("Serial Number").GetText
        
    
    
    Next Cmd


    This is what I have so far...

    Gotta be able to pull the tracefield value from the part program and assign to the VSERIALNUMBER variable in the script.
    The line: "VSERIALNUMBER = TCmd("Serial Number").GetText" is throwing an Object Variable error "Not Set"
  • You need to check first that the current command is a tracefield command by using the "if cmd.istracefield" logic shown above.

    Otherwise the tracefield member of the current command will be empty resulting in the error you are getting.

    Sent from my SPH-L710 using Tapatalk
  • You need to check first that the current command is a tracefield command by using the "if cmd.istracefield" logic shown above.

    Otherwise the tracefield member of the current command will be empty resulting in the error you are getting.

    Sent from my SPH-L710 using Tapatalk


    Thanks DJAMS. Now it's throwing the OLE error... no default value.

    But that's the whole point. I don't need a "default value". I want to read in the value from the PRG. I suck at scripts.

    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 Object
    
    For Each Cmd In Cmds
       If Cmd.IsTracefield Then
       Set TCmd = Cmd.TraceFieldCommand
    
    Set VSERIALNUMBER = TCmd("Serial Number").GetText
        
    End If
    
    
    Next Cmd
    
  • Try DIMing the VSERIALNUMBER as a string, and lose the "Set" before VSERIALNUMBER when you assign it.
  • If TraceCommand.Name = "Serial Number" Then
    do something with TraceCommand.Value
    End if

    You will need to be careful to compare things correctly, spaces, capital, etc.
  • Thanks guys. I'll try that in the morning


    Sent from my iPhone using Tapatalk
  • No luck with either suggestion guys. This is maddening...