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...
  • No luck with either suggestion guys. This is maddening...


    You need to help us help you. . . Please post your code here so we can see if we recognize a syntax error, or code error. Also a little more detail on the "No Luck. . ." might be helpful. Did it run and not do anything? Did it return an error? Did it do anything but just not what you wanted?
  • You need to help us help you. . . Please post your code here so we can see if we recognize a syntax error, or code error. Also a little more detail on the "No Luck. . ." might be helpful. Did it run and not do anything? Did it return an error? Did it do anything but just not what you wanted?


    Sub Main
    
    
    
    'Declares the File System Object And Instantiates it
     Dim objFSO
     objFSO = CreateObject("Scripting.FileSystemObject")
            
    
    
    '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 Object
    
        For Each Cmd In Cmds
              If Cmd.IsTraceField Then
              Set TCmd = Cmd.TraceFieldCommand
              End If
    
              If TCmd.Name = "Serial Number" Then (this is line 28)
              VSERIALNUMBER = TCmd.Value
        End If
    
    Next Cmd
    
    
    End Sub
    


    Runtime Error on line:28 - Object variable or With block variable not set
  • 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
  • The value returned in the MsgBox was correct, Don. Thanks.

    Sub Main()
    
    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    '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 VPART, VDESCRIPTION, VPROGRAMID, VPROGRAMREV As Object
    Dim VSERIALNUMBER As String
    Dim RESULTS As String
    
    Set VPART = Part.GetVariableValue ("VPART")
    Set VDESCRIPTION = Part.GetVariableValue ("VDESCRIPTION")
    Set VPROGRAMID = Part.GetVariableValue ("VPROGRAMID")
    Set VPROGRAMREV = Part.GetVariableValue ("VPROGRAMREV")
    
    
        For Each Cmd In Cmds
              If Cmd.IsTraceField Then
      
              If Cmd.GetText(TRACE_NAME, 0) = "Serial Number" Then
                    VSERIALNUMBER = Cmd.GetText(TRACE_VALUE, 0)
                    
              End If
    
     End If
    
    Next Cmd
    
    strPath = "D:\\CMM_PROGRAMS\\" & VPART.StringValue & "_" & VDESCRIPTION.StringValue & "_" & VPROGRAMID.StringValue & "_" & VPROGRAMREV.StringValue
    strFldrPath = strPath & "\" & "RESULTS\"
    strFldrName = VSERIALNUMBER
    
    strFldr = strFldrPath & StrFlrName
    
    objFolder = objFSO.CreateFolder(strFldr)    [this is line 44]
    
    End Sub


    Only problem now is that an automation error (line 44) with the folder creation command.
  • Maybe the folder already exist?


    I thought that too. No folder...

    I have a similar script that is in use in production as we speak. It works without fail. However, I tried that script in my current situation (using BladeRunner) and it gives me the same error: OLE Automation error.

    Could BladeRunner be blocking the function of the script somehow?
  • Not sure if this could be the source of the problem, but:

    strFl[COLOR="#FF0000"]d[/COLOR]rName = VSERIALNUMBER
    
    strFldr = strFldrPath & [COLOR="#FF0000"]StrFlrName[/COLOR]
    objFolder = objFSO.CreateFolder(strFldr)    [this is line 44]


    There seems to be missing a 'd' in the concatenation of "strFldr" (see above).
  • Good catch.

    Still throwing the error however.
  • Another long shot:

    Change:
    objFolder = objFSO.CreateFolder(strFldr)


    To:
    [COLOR="#FF0000"]Set[/COLOR] objFolder = objFSO.CreateFolder(strFldr)