hexagon logo

Save reports in PDF automatically and use date and time as name

Hi,

I want to save the reports automatically after every run and use date and time for the name file. How I can do that?

Thanks!
Parents
  • I hate to re-hash this, but I've tried everything I know (plus a ton of Google searches to the forum) to get my program to auto-save based on operator inputs (Job #/ Sample number).
    Right now, at the end of the program, the operator just names the report based on the sample number. However, they are prone to not pay attention to where they are saving, and once they save it to the wrong folder, it's next to impossible to find the report. So, i was trying to name the report by this standard:

    <Program Folder>/Reports/<Part Number>_<Job Number>_<Date>_<Sample Number>.pdf


    Here is the top of the program, where the operator is asked to input the job number, sample number, and operator initials...

    STARTUP    =ALIGNMENT/START,RECALL:USE_PART_SETUP,LIST=YES
                ALIGNMENT/END
                MODE/MANUAL
                FORMAT/TEXT,OPTIONS,ID,HEADINGS,SYMBOLS, ;NOM,TOL,MEAS,MAXMIN,DEV,DEVANG,OUTTOL
                MOVESPEED/ 200
                FORMAT/TEXT,OPTIONS, ,HEADINGS,SYMBOLS, ;NOM,TOL,MEAS,DEV,OUTTOL, ,
                COMMENT/OPER,YES,FULL SCREEN=YES,AUTO-CONTINUE=NO,
                ****TEST PROGRAM OFFLINE ONLY NOT FOR FAIs/IPs****
                LOADPROBE/EPS POINT5X20
                TIP/T1A0B0, SHANKIJK=0, 0, 1, ANGLE=0
                COMMENT/OPER,NO,FULL SCREEN=YES,AUTO-CONTINUE=NO,
                PLACE PART IN RAPTOR FIXTURE AS SHOWN.
                PLACE PEGS AT I-4, I-9, & H-11.
    C1         =COMMENT/INPUT,YES,FULL SCREEN=NO,
                INPUT JOB NUMBER
                ASSIGN/V2=C1.INPUT
    C3         =COMMENT/INPUT,YES,FULL SCREEN=NO,
                INPUT PART COUNT
                ASSIGN/V1=C3.INPUT
    C2         =COMMENT/INPUT,YES,FULL SCREEN=NO,
                INPUT OPERATOR  
                ASSIGN/V3=C2.INPUT
                LOADPROBE/EPS POINT5X20
                TIP/T1A0B0, SHANKIJK=0, 0, 1, ANGLE=0
    MANALIN    =COMMENT/YESNO,NO,FULL SCREEN=YES,AUTO-CONTINUE=NO,
                
                
                DO YOU NEED TO RUN MANUAL ALIGNMENT?
                
                ​



    Here is the end of the program with the attempt to auto-name, where it calls up the variables to create the folder path, name the file, and saves the report to PDF (the FreeBasic scripts are below the program code):

    END =GROUP/SHOWALLPARAMS=YES
    COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
    **END OF PROGRAM HERE**
    SAVE_REPORT =GROUP/SHOWALLPARAMS=YES
    $$ NO,
    --------------------------------------------------------
    UPDATE FOLDERPATH inside of tracefield below TO ACTUAL REPORT
    location (COPY AND PASTE AND ADD A "/" TO THE END) for
    PART SPECIFIC LOCATION example below
    "M:\DMR\CMM PROGRAMS\>cust name<\>part num<\REPORTS/"
    --------------------------------------------------------
    ASSIGN/FOLDERPATH="O:\EMPLOYEE FOLDER\GREBE\_CMM_TEST\EPS-C1054-3-N REV A"
    WORKPLANE/ZPLUS
    ASSIGN_FILENAME =GROUP/SHOWALLPARAMS=YES
    ASSIGN/FOLDERNAME=FOLDERPATH+"\REPORTS\"+V2+"\"
    ENDGROUP/ID=ASSIGN_FILENAME
    ASSIGN/PRINT_PATH=FOLDERNAME+GETPROGRAMINFO("PARTNAME")+" _"+ V2+"_"+SYSTIME()+"_"+V1+".PDF"
    CREATE_FOLDER =GROUP/SHOWALLPARAMS=YES
    $$ NO,
    --------------------------------------------------------------
    CREATES THE FOLDER, IF NEEDED.
    WILL POP UP A WARNING IF FOLDER IS ALREADY CREATED,
    CLICK OK ON DIALOG BOX TO CONTINUE
    --------------------------------------------------------------
    CS1 =SCRIPT/FILENAME= "M:\DMR\CMM PROGRAMS\_SCRIPTS\CREATE.BAS"
    FUNCTION/PCDCreatefolder,SHOW=YES,ARG1=PRINT_PATH,,
    STARTSCRIPT/
    ENDGROUP/ID=CREATE_FOLDER
    REDRAW =GROUP/SHOWALLPARAMS=YES
    $$ NO,
    Redraws the Report Window before saving.
    CS2 =SCRIPT/FILENAME= "M:\DMR\CMM PROGRAMS\_SCRIPTS\REDRAW.BAS"
    FUNCTION/Main,SHOW=YES,,
    STARTSCRIPT/
    ENDGROUP/ID=REDRAW
    SAVE_PDF =GROUP/SHOWALLPARAMS=YES
    PRINT/REPORT,EXEC MODE=END,$
    TO_FILE=ON,AUTO=PRINT_PATH,AUTO OPEN=OFF,$
    TO_PRINTER=OFF,COPIES=1,$
    TO_DMIS_REPORT=OFF,FILE_OPTION=OVERWRITE,FILENAME= FOLDERNAME,$
    REPORT_THEORETICALS=NONE,REPORT_FEATURE_WITH_DIMEN SIONS=NO,$
    TO_EXCEL=OFF,$
    PREVIOUS_RUNS=DELETE_INSTANCES
    ENDGROUP/ID=SAVE_PDF
    ENDGROUP/ID=SAVE_REPORT
    ENDGROUP/ID=END
    


    Here are the 2 scripts i created, one to create the folder, and the later to "redraw" the report:

    '
    ' CREATED BY B. GREBE 21 AUG 23
    ' CODE SOURCE: PC-DMIS ONLINE FORUM (FREE USE)
    ' LANGUAGE: FREEBASIC (For PC-DMIS)
    ' Function: To CREATE THE SAVE FOLDER For THE PDF CMM REPORT
    '
    Sub Main()
    
    Dim objFSO, objShell
    Dim PCDApp, PCDPartProgram, PCDCommands, PCDCommand, retval
    Dim objFile, objFolder As Object
    
    Set PCDApp=CreateObject("PCDLRN.Application")
    Set PCDPartProgram=PCDApp.ActivePartProgram
    Set PCDCommands=PCDPartProgram.Commands
    
    'Grabs FolderName from PCD part program
    
    Set Pathname=PCDPartProgram.GetVariableValue("FOLDERNAME")
    
    'Sets Pathname As String value
    
    strPath=Pathname.StringValue
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Creates folder On Netowrk Drive If Needed
    
    If objFSO.FolderExists(strPath) Then
    'Nothing
    Else
    Set objFile=objFSO.CreateFolder(strPath)
    End If
    
    'Cleanup
    Set pcdReportWindow = Nothing
    Set pcdPart = Nothing
    Set pcdApp = Nothing
    Set Pathname = Nothing
    Set objFSO = Nothing
    
    End Sub​


    '
    ' CREATED BY B. GREBE 21 AUG 23
    ' CODE SOURCE: PC-DMIS ONLINE FORUM (FREE USE)
    ' LANGUAGE: FREEBASIC (FOR PC-DMIS)
    ' FUNCTION: TO 'REDRAW' THE CMM REPORT PRIOR TO SAVING
    '
    Sub Main()
    
    
    '************PC-DMIS declarations************
    Dim pcdApp As Object
    Set pcdApp = CreateObject("PCDLRN.Application")
    
    Dim pcdPart As Object
    Set pcdPart = pcdApp.ActivePartProgram
    
    Dim pcdReportWindow As Object
    Set pcdReportWindow = pcdPart.ReportWindow
    
    '***********Repaint the report window*********
    pcdReportWindow.RefreshReport
    
    '********************Cleanup**********************
    Set pcdReportWindow = Nothing
    Set pcdPart = Nothing
    Set pcdApp = Nothing
    
    End Sub​


    Maybe i'm in over my head, or just a small oversight error...
    Thanks in advance.
Reply
  • I hate to re-hash this, but I've tried everything I know (plus a ton of Google searches to the forum) to get my program to auto-save based on operator inputs (Job #/ Sample number).
    Right now, at the end of the program, the operator just names the report based on the sample number. However, they are prone to not pay attention to where they are saving, and once they save it to the wrong folder, it's next to impossible to find the report. So, i was trying to name the report by this standard:

    <Program Folder>/Reports/<Part Number>_<Job Number>_<Date>_<Sample Number>.pdf


    Here is the top of the program, where the operator is asked to input the job number, sample number, and operator initials...

    STARTUP    =ALIGNMENT/START,RECALL:USE_PART_SETUP,LIST=YES
                ALIGNMENT/END
                MODE/MANUAL
                FORMAT/TEXT,OPTIONS,ID,HEADINGS,SYMBOLS, ;NOM,TOL,MEAS,MAXMIN,DEV,DEVANG,OUTTOL
                MOVESPEED/ 200
                FORMAT/TEXT,OPTIONS, ,HEADINGS,SYMBOLS, ;NOM,TOL,MEAS,DEV,OUTTOL, ,
                COMMENT/OPER,YES,FULL SCREEN=YES,AUTO-CONTINUE=NO,
                ****TEST PROGRAM OFFLINE ONLY NOT FOR FAIs/IPs****
                LOADPROBE/EPS POINT5X20
                TIP/T1A0B0, SHANKIJK=0, 0, 1, ANGLE=0
                COMMENT/OPER,NO,FULL SCREEN=YES,AUTO-CONTINUE=NO,
                PLACE PART IN RAPTOR FIXTURE AS SHOWN.
                PLACE PEGS AT I-4, I-9, & H-11.
    C1         =COMMENT/INPUT,YES,FULL SCREEN=NO,
                INPUT JOB NUMBER
                ASSIGN/V2=C1.INPUT
    C3         =COMMENT/INPUT,YES,FULL SCREEN=NO,
                INPUT PART COUNT
                ASSIGN/V1=C3.INPUT
    C2         =COMMENT/INPUT,YES,FULL SCREEN=NO,
                INPUT OPERATOR  
                ASSIGN/V3=C2.INPUT
                LOADPROBE/EPS POINT5X20
                TIP/T1A0B0, SHANKIJK=0, 0, 1, ANGLE=0
    MANALIN    =COMMENT/YESNO,NO,FULL SCREEN=YES,AUTO-CONTINUE=NO,
                
                
                DO YOU NEED TO RUN MANUAL ALIGNMENT?
                
                ​



    Here is the end of the program with the attempt to auto-name, where it calls up the variables to create the folder path, name the file, and saves the report to PDF (the FreeBasic scripts are below the program code):

    END =GROUP/SHOWALLPARAMS=YES
    COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
    **END OF PROGRAM HERE**
    SAVE_REPORT =GROUP/SHOWALLPARAMS=YES
    $$ NO,
    --------------------------------------------------------
    UPDATE FOLDERPATH inside of tracefield below TO ACTUAL REPORT
    location (COPY AND PASTE AND ADD A "/" TO THE END) for
    PART SPECIFIC LOCATION example below
    "M:\DMR\CMM PROGRAMS\>cust name<\>part num<\REPORTS/"
    --------------------------------------------------------
    ASSIGN/FOLDERPATH="O:\EMPLOYEE FOLDER\GREBE\_CMM_TEST\EPS-C1054-3-N REV A"
    WORKPLANE/ZPLUS
    ASSIGN_FILENAME =GROUP/SHOWALLPARAMS=YES
    ASSIGN/FOLDERNAME=FOLDERPATH+"\REPORTS\"+V2+"\"
    ENDGROUP/ID=ASSIGN_FILENAME
    ASSIGN/PRINT_PATH=FOLDERNAME+GETPROGRAMINFO("PARTNAME")+" _"+ V2+"_"+SYSTIME()+"_"+V1+".PDF"
    CREATE_FOLDER =GROUP/SHOWALLPARAMS=YES
    $$ NO,
    --------------------------------------------------------------
    CREATES THE FOLDER, IF NEEDED.
    WILL POP UP A WARNING IF FOLDER IS ALREADY CREATED,
    CLICK OK ON DIALOG BOX TO CONTINUE
    --------------------------------------------------------------
    CS1 =SCRIPT/FILENAME= "M:\DMR\CMM PROGRAMS\_SCRIPTS\CREATE.BAS"
    FUNCTION/PCDCreatefolder,SHOW=YES,ARG1=PRINT_PATH,,
    STARTSCRIPT/
    ENDGROUP/ID=CREATE_FOLDER
    REDRAW =GROUP/SHOWALLPARAMS=YES
    $$ NO,
    Redraws the Report Window before saving.
    CS2 =SCRIPT/FILENAME= "M:\DMR\CMM PROGRAMS\_SCRIPTS\REDRAW.BAS"
    FUNCTION/Main,SHOW=YES,,
    STARTSCRIPT/
    ENDGROUP/ID=REDRAW
    SAVE_PDF =GROUP/SHOWALLPARAMS=YES
    PRINT/REPORT,EXEC MODE=END,$
    TO_FILE=ON,AUTO=PRINT_PATH,AUTO OPEN=OFF,$
    TO_PRINTER=OFF,COPIES=1,$
    TO_DMIS_REPORT=OFF,FILE_OPTION=OVERWRITE,FILENAME= FOLDERNAME,$
    REPORT_THEORETICALS=NONE,REPORT_FEATURE_WITH_DIMEN SIONS=NO,$
    TO_EXCEL=OFF,$
    PREVIOUS_RUNS=DELETE_INSTANCES
    ENDGROUP/ID=SAVE_PDF
    ENDGROUP/ID=SAVE_REPORT
    ENDGROUP/ID=END
    


    Here are the 2 scripts i created, one to create the folder, and the later to "redraw" the report:

    '
    ' CREATED BY B. GREBE 21 AUG 23
    ' CODE SOURCE: PC-DMIS ONLINE FORUM (FREE USE)
    ' LANGUAGE: FREEBASIC (For PC-DMIS)
    ' Function: To CREATE THE SAVE FOLDER For THE PDF CMM REPORT
    '
    Sub Main()
    
    Dim objFSO, objShell
    Dim PCDApp, PCDPartProgram, PCDCommands, PCDCommand, retval
    Dim objFile, objFolder As Object
    
    Set PCDApp=CreateObject("PCDLRN.Application")
    Set PCDPartProgram=PCDApp.ActivePartProgram
    Set PCDCommands=PCDPartProgram.Commands
    
    'Grabs FolderName from PCD part program
    
    Set Pathname=PCDPartProgram.GetVariableValue("FOLDERNAME")
    
    'Sets Pathname As String value
    
    strPath=Pathname.StringValue
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Creates folder On Netowrk Drive If Needed
    
    If objFSO.FolderExists(strPath) Then
    'Nothing
    Else
    Set objFile=objFSO.CreateFolder(strPath)
    End If
    
    'Cleanup
    Set pcdReportWindow = Nothing
    Set pcdPart = Nothing
    Set pcdApp = Nothing
    Set Pathname = Nothing
    Set objFSO = Nothing
    
    End Sub​


    '
    ' CREATED BY B. GREBE 21 AUG 23
    ' CODE SOURCE: PC-DMIS ONLINE FORUM (FREE USE)
    ' LANGUAGE: FREEBASIC (FOR PC-DMIS)
    ' FUNCTION: TO 'REDRAW' THE CMM REPORT PRIOR TO SAVING
    '
    Sub Main()
    
    
    '************PC-DMIS declarations************
    Dim pcdApp As Object
    Set pcdApp = CreateObject("PCDLRN.Application")
    
    Dim pcdPart As Object
    Set pcdPart = pcdApp.ActivePartProgram
    
    Dim pcdReportWindow As Object
    Set pcdReportWindow = pcdPart.ReportWindow
    
    '***********Repaint the report window*********
    pcdReportWindow.RefreshReport
    
    '********************Cleanup**********************
    Set pcdReportWindow = Nothing
    Set pcdPart = Nothing
    Set pcdApp = Nothing
    
    End Sub​


    Maybe i'm in over my head, or just a small oversight error...
    Thanks in advance.
Children