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...
  • Another long shot:

    Change:
    objFolder = objFSO.CreateFolder(strFldr)


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


    Yea it's still throwing the error... I've never had this much trouble. There should be nothing wrong with the code...

    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 & StrFldrName
    
    Set objFldr = objFSO.CreateFolder(strFldr)
    
    End Sub
  • Hmm... Are you sure you have an identical script running OK?

    I assume you are running this as a PC-DMIS script, but you are throwing in a FileSystemObject (Visual Basic Scripting) so I am thinking that in order to use that from within PC-DMIS, you might need to to do some additional coding to expose the VBS objects through PC-DMIS basic.

    For testing, I used this snippet running as a script in PC-DMIS:
    Sub Main()
    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFldr = objFSO.CreateFolder("C:\test")
    End Sub
    


    This threw an automation object error.
    Now, using the same script (slightly modified) and executed it as a VBS script:

    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFldr = objFSO.CreateFolder("C:\test")


    ...works just fine.

    So, I believe that in order to use "out-of-process" objects, you'd need to code them differently (look in the PC-DMIS basic helpfile), or code the script as a VBS-script and call that from within PC-DMIS.
  • This is the script I mentioned earlier. It is working on every production part we have run since implementation.

    HOWEVER, THIS SCRIPT WILL NOT RUN IN BLADERUNNER. IT DOES WORK IN PC-DMIS. That's why I mentioned that earilier.

    Sub Main
    
    'Declares the File System Object And Instantiates it
    Dim  objFSO
    Set  objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Declares PC-DMIS As the Active Program/Application
    Dim PCDApp, PCDPartProgram, PCDCommands, PCDCommand, retval
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set Part = PCDApp.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands
    
    'Declares Variables from the prg As Objects
    
    Dim VPART As Object
    Dim VDESCRIPTION As Object
    Dim VSERIALNUMBER As Object
    Dim VDATE As Object
    Dim RESULTS As String
    
    
    'Pulls the variables from the prg
    
    Set  VPART = Part.GetVariableValue ("VPART")
    Set  VDESCRIPTION = Part.GetVariableValue ("VDESCRIPTION")
    Set VSERIALNUMBER = Part.GetVariableValue ("VSERIALNUMBER")
    Set VDATE = Part.GetVariableValue ("VDATE")
    
    'Declares the Filepath, Folder, And the Filename As a String
    
    strPath = Part.Path     'Uses the prg path As the path For the folder
    
    
    'Sets the folder Name And the Path For the Folder
    strFolderName = VPART.StringValue & "_" & VDESCRIPTION.StringValue & "_" & VSERIALNUMBER.StringValue & "_" & VDATE.StringValue
    strFolder = strPath & "RESULTS\" & strFolderName
    
    If  objFSO.FolderExists(strFolder) Then  GoTo  labelEnd
    
    'This command creates the folder
    objFolder = objFSO.CreateFolder(strFolder)
    
    labelEnd
        
    
    End Sub
    
  • A couple of thoughts.

    1) For "strPath=" you are using \\ for folder delimiter and for "strFldrName=" you are using \ - I think the single slash is correct.

    2) The path must be created step by step - for instance, if I want to create "C:\F1\F2\", F2 can't be created if F1 doesn't exist.

    3) If string content in any of the variables you are using contain these characters " \ / : * ? " < > | " you will get an error since they are invalid for file names.


    So, I believe that in order to use "out-of-process" objects, you'd need to code them differently (look in the PC-DMIS basic helpfile), or code the script as a VBS-script and call that from within PC-DMIS.


    We have many scripts that use FileSystemObject - I've never had to do anything out of the ordinary. I don't understand why your pc-dmis example above errored out.Confused
  • The folder hierarchy is different between the two scripts you've posted - is this intentional?
  • The folder hierarchy is different between the two scripts you've posted - is this intentional?


    Different how?

    1) For "strPath=" you are using \\ for folder delimiter and for "strFldrName=" you are using \ - I think the single slash is correct.


    Corrected this issue and still OLE automation method exception.
  • Different how?


    In the script you are working on you have

    D:\CMM_PROGRAMS\DIRECTORY_FROM_A_BUNCH_OF_VARIABLES\ RESULTS\

    In the script that works (except in bladerunner) you have

    Part.Path\ RESULTS\DIRECTORY_FROM_A_BUNCH_OF_VARIABLES\

    Where Part.Path is the directory the part program lives in. I was just noticing that the RESULTS folder is in a different spot.

    edit: I tested the \\ vs \ thing - it seems that it doesn't matter. It works either way.
  • We have many scripts that use FileSystemObject - I've never had to do anything out of the ordinary. I don't understand why your pc-dmis example above errored out.Confused


    Yes, it is weird at least...
  • In the script you are working on you have

    D:\CMM_PROGRAMS\DIRECTORY_FROM_A_BUNCH_OF_VARIABLES\ RESULTS\

    In the script that works (except in bladerunner) you have

    Part.Path\ RESULTS\DIRECTORY_FROM_A_BUNCH_OF_VARIABLES\

    Where Part.Path is the directory the part program lives in. I was just noticing that the RESULTS folder is in a different spot.

    edit: I tested the \\ vs \ thing - it seems that it doesn't matter. It works either way.


    The folders are in the same spot. The reason I didn't use the Part.Path is that BladeRunner copies the chosen program and runs it in a "temp" folder. It would interpret Part.Path as the temp folder.
  • The folders are in the same spot. The reason I didn't use the Part.Path is that BladeRunner copies the chosen program and runs it in a "temp" folder. It would interpret Part.Path as the temp folder.

    Part.Path is not what I meant to point out. It's the sequence of the directories following that. Your new code is building a different path than the script that works.