hexagon logo

Using script to create folder for prg and save part program

Been reading up on the script manual (PC-DMIS) 3.6 Basic Language Reference Manual) trying to figure out how to get the script to create a folder for the report, the .prg, and any other files associated with the program by serial number of the part.

For example:
PART#_DESCRIPTION_SERIAL#_DATE_TIME

The goal is to write a script contained in the .prg that, upon execution of the part program, will create a folder in a specified directory with the variable filename using the inputs from the part program and save the .prg with the same name.

How would I pass the information from the operator inputs of the part program into the script to make this happen?
Parents
  • The previous code worked, but was unstable. I have a revised version below for anyone who is interested...

    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 VTIME 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")
    Set  VTIME = Part.GetVariableValue ("VTIME")
    
    '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 Not objFSO.FolderExists(strFolder) Then
    
    'This command creates the folder
    Set objFolder = objFSO.CreateFolder(strFolder)
    
    End If
    
    'CLEANUP And SCRIPT Close
    Set PART = Nothing
    Set PCDApp = Nothing
    
    
    End Sub
    
Reply
  • The previous code worked, but was unstable. I have a revised version below for anyone who is interested...

    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 VTIME 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")
    Set  VTIME = Part.GetVariableValue ("VTIME")
    
    '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 Not objFSO.FolderExists(strFolder) Then
    
    'This command creates the folder
    Set objFolder = objFSO.CreateFolder(strFolder)
    
    End If
    
    'CLEANUP And SCRIPT Close
    Set PART = Nothing
    Set PCDApp = Nothing
    
    
    End Sub
    
Children
No Data