hexagon logo

help, auto save .prg after run, in a specific location variable.

I have been looking through all the past topics about this. but I am having trouble getting them working. I tried copy and pasting a few of them. and saving them as a .bas file and running the script. but i cant get one to work for me.


i currently already have a script that auto creates a folder from an operator input and saves the cmm report in that folder.

so ideally i want to follow that same train of thought and save a .prg & .cad in that same folder already created.


please advice.

Parents
  • By any chance would anyone else be able to offer a suggestion as to what I'm doing wrong here? I'm attempting to check for an existing folder in Q:\Quality\In Process Inspection Plans\11127-MACHINE\CMM REPORTS for a folder named for the Job Number. If the folder exists, I'm wanting to save both the readout and the program in this folder with the serial number for the part attached to the end of each to differentiate each one from the readout and program saved for the other parts with differing serial number but are under the same job(work order).
    I had the code working to save the program in the CMM REPORTS folder, but when I attempted to modify it to put it in the folder that was created using the Job number, it gave me an "OLE Automation method exception" error on the line beginning with "newname". I'm not sure if I'm not setting the file path up correctly or what exactly I'm doing wrong, but any help would be appreciated...

    [SIZE=14px][FONT=times new roman][COLOR=#0000ff][COLOR=#0000ff]Sub[/COLOR][/COLOR] Main()
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] PCDApp,PCDPartProgram, PCDCommands, PCDCommand, retval
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] objFSO
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] objFSO = CreateObject ("Scripting.FileSystemObject")
    
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PCDApp = CreateObject("PCDLRN.Application")
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PCDPartPrograms = PCDApp.PartPrograms
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PCDPartProgram = PCDApp.ActivePartProgram
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] Cmds [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Object[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] Cmd [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Object[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] Cmds = PCDPartProgram.Commands
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] setCrntName [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]String[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] PartNo [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Object[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] JobNo [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Object[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] SerNo [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Object[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] SerialNo [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]String[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] Results [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]String[/COLOR][/COLOR]
    
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PartNo = PCDPartProgram.GetVariableValue ("V5")
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] JobNo = PCDPartProgram.GetVariableValue ("V1")
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] SerNo = PCDPartProgram.GetVariableValue ("V2")
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] Serial = PCDPartProgram.GetVariableValue ("V2")
    
    strPath = "Q:\Quality\In Process Inspection Plans\PartNo.StringValue\CMM REPORTS\"
    strFolderName = JobNo.StringValue & "_" & SerNo.StringValue
    strFolder = strPath & "\RESULTS\" & strFolderName
    
    [COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Not[/COLOR][/COLOR] objFSO.FolderExists(strFolder) [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] objFolder = objFSO.CreateFolder(strFolder)
    
    [COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR]
    
    SerialNo = Serial.StringValue
    setCrntName = PCDPartProgram.FullName
    newname = "Q:\Quality\In Process Inspection Plans\" & PartNo.StringValue & "\CMM REPORTS\ObjFolder\" & PCDPartProgram.PartName & " - " & SerialNo & ".PRG"
    
    retval = PCDPartProgram.SaveAs(newname)
    retval = PCDPartProgram.SaveAs(setCrntName)
    
    [COLOR=#007f00][COLOR=#007f00]' Cleanup [/COLOR][/COLOR]
    
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PCDPartProgram = [COLOR=#0000ff][COLOR=#0000ff]Nothing[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PCDPartPrograms = [COLOR=#0000ff][COLOR=#0000ff]Nothing[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PCDApp = [COLOR=#0000ff][COLOR=#0000ff]Nothing[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Sub[/COLOR][/COLOR][/FONT][/SIZE]
    
Reply
  • By any chance would anyone else be able to offer a suggestion as to what I'm doing wrong here? I'm attempting to check for an existing folder in Q:\Quality\In Process Inspection Plans\11127-MACHINE\CMM REPORTS for a folder named for the Job Number. If the folder exists, I'm wanting to save both the readout and the program in this folder with the serial number for the part attached to the end of each to differentiate each one from the readout and program saved for the other parts with differing serial number but are under the same job(work order).
    I had the code working to save the program in the CMM REPORTS folder, but when I attempted to modify it to put it in the folder that was created using the Job number, it gave me an "OLE Automation method exception" error on the line beginning with "newname". I'm not sure if I'm not setting the file path up correctly or what exactly I'm doing wrong, but any help would be appreciated...

    [SIZE=14px][FONT=times new roman][COLOR=#0000ff][COLOR=#0000ff]Sub[/COLOR][/COLOR] Main()
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] PCDApp,PCDPartProgram, PCDCommands, PCDCommand, retval
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] objFSO
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] objFSO = CreateObject ("Scripting.FileSystemObject")
    
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PCDApp = CreateObject("PCDLRN.Application")
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PCDPartPrograms = PCDApp.PartPrograms
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PCDPartProgram = PCDApp.ActivePartProgram
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] Cmds [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Object[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] Cmd [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Object[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] Cmds = PCDPartProgram.Commands
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] setCrntName [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]String[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] PartNo [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Object[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] JobNo [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Object[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] SerNo [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Object[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] SerialNo [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]String[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] Results [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]String[/COLOR][/COLOR]
    
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PartNo = PCDPartProgram.GetVariableValue ("V5")
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] JobNo = PCDPartProgram.GetVariableValue ("V1")
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] SerNo = PCDPartProgram.GetVariableValue ("V2")
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] Serial = PCDPartProgram.GetVariableValue ("V2")
    
    strPath = "Q:\Quality\In Process Inspection Plans\PartNo.StringValue\CMM REPORTS\"
    strFolderName = JobNo.StringValue & "_" & SerNo.StringValue
    strFolder = strPath & "\RESULTS\" & strFolderName
    
    [COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Not[/COLOR][/COLOR] objFSO.FolderExists(strFolder) [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] objFolder = objFSO.CreateFolder(strFolder)
    
    [COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR]
    
    SerialNo = Serial.StringValue
    setCrntName = PCDPartProgram.FullName
    newname = "Q:\Quality\In Process Inspection Plans\" & PartNo.StringValue & "\CMM REPORTS\ObjFolder\" & PCDPartProgram.PartName & " - " & SerialNo & ".PRG"
    
    retval = PCDPartProgram.SaveAs(newname)
    retval = PCDPartProgram.SaveAs(setCrntName)
    
    [COLOR=#007f00][COLOR=#007f00]' Cleanup [/COLOR][/COLOR]
    
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PCDPartProgram = [COLOR=#0000ff][COLOR=#0000ff]Nothing[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PCDPartPrograms = [COLOR=#0000ff][COLOR=#0000ff]Nothing[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]Set[/COLOR][/COLOR] PCDApp = [COLOR=#0000ff][COLOR=#0000ff]Nothing[/COLOR][/COLOR]
    [COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Sub[/COLOR][/COLOR][/FONT][/SIZE]
    
Children
No Data