hexagon logo

Saving Pdf and Csv reports without prompting the user

Currently I am trying to write a C# app that will run a PCDmis program and then save the reports with specific names, in a specific folder based on some inputs from another source. I found an example of what I'm trying to do but it involves changing the prg file directly and I was wondering if I can do the same thing in C#?

I found this code from from 2021 but it's an embedded script.

GROUP_PRINT_COMMANDS=GROUP/SHOWALLPARAMS=YES
ASSIGN/NUMOOT=GETPROGRAMINFO("NUMOOT")
ASSIGN/PROG_NAME=GETPROGRAMINFO ("PARTNAME")
ASSIGN/DATE=STR(SYSTEMDATE ("dMMMyyyy"))
ASSIGN/TIME=STR(SYSTEMTIME ("HHmmss"))
ASSIGN/REJECT="____REJECT____"
IF/NUMOOT=="0"
ASSIGN/REPORT_NAME="O:\\CMM PROGRAMS\\CMM_PDF_PC DMIS\\AG0OFFLINETEST\\"+PROG_NAME+"__"+VAR_SERIAL_ NUMBER+"__"+VAR_RUNNUMBER+"__"+DATE+"__"+TIME+"__. PDF"
END_IF/
ELSE/
ASSIGN/REPORT_NAME="O:\\CMM PROGRAMS\\CMM_PDF_PC DMIS\\AG0OFFLINETEST\\"+PROG_NAME+"__"+VAR_SERIAL_ NUMBER+"__"+VAR_RUNNUMBER+"__"+DATE+"__"+TIME+"__" +REJECT+".PDF"
END_ELSE/
PRINT/REPORT,EXEC MODE=END,$
TO_FILE=ON,AUTO=1,AUTO OPEN=OFF,$
TO_PRINTER=OFF,COPIES=1,$
TO_DMIS_REPORT=OFF,FILE_OPTION=OVERWRITE,FILENAME= [B]REPORT_NAME[/B],$
REPORT_THEORETICALS=NONE,REPORT_FEATURE_WITH_DIMENSIONS=NO,$
TO_EXCEL=OFF,$
PREVIOUS_RUNS=KEEP_INSTANCES
ENDGROUP/ID=GROUP_PRINT_COMMANDS
Parents
  • Hello,


    "TO_FILE=" Line for PDF output
    -> "APPEND=" means he is trying to append the measurement data to an existing PDF file, is that intentional? If the path is wrong or the file doesn't exist, it simply doesn't do anything

    "TO_PRINTER=" he is trying to print to a real printer.

    "TO_DMIS_REPORT=" Line for *.dmo files -> "FILENAME=REPORT_NAME" in this line does nothing, because "TO_DMIS_REPORT=OFF"
    -> REPORT_NAME is a pcDMIS-Variable
    -> B is forum formating and can be deleted

    "TO_EXCEL=" Line for Excel and CSV output files

    ################################################## ####################################

    in your example it ONLY tries to attach the measurement data to a PDF called #1.pdf
    all other lines are =OFF

    if you keep assigning a new file (a new Number) name via your external program, then "OVERWRITE" is the correct procedure.
    File extension ".PDF" is not required
    File extension ".CSV" is required in Excel Line

    Code for PDF ONLY
    Set DmisCommand = DmisCommands.Add(PRINT_REPORT, TRUE)
    DmisCommand.Marked = TRUE
    
      ' Line for PDF-File output
        retval = DmisCommand.SetToggleString (2, PRINT_TO_FILE, 0) ' Set Print To File  = ON
        retval = DmisCommand.PutText ("C:\Users\QS\Desktop\MigrationsTools\test123", FILE_NAME, 1) '<- change PDF path here, ("test123" is indeed the filename)
        retval = DmisCommand.SetToggleString (2, FILE_COMMAND_TYPE, 0) ' Set File Print Method  = OVERWRITE
        retval = DmisCommand.SetToggleString (1, ONOFF_TYPE, 0)  ' Set Auto Open  = OFF
    
      ' Line for Printer output
        retval = DmisCommand.SetToggleString (1, PRINT_TO_PRINTER, 0) ' Set Print To Printer  = OFF
        retval = DmisCommand.PutText ("1", INDEX_END, 0)  ' Set Number Of Copies  = 1
        retval = DmisCommand.SetToggleString (1, PRINT_DELETE_RUNS, 0) ' Set Previous Runs  = DELETE_INSTANCES
    
      ' Line for *.dmo file output
        retval = DmisCommand.SetToggleString (1, OUTPUT_DMIS_REPORT, 0) ' Set DMIS Output  = OFF
        retval = DmisCommand.SetToggleString (1, OVERWRITE, 0)   ' Set Overwrite  = INDEX
        retval = DmisCommand.SetToggleString (1, OUTPUT_FEATURE_NOMS, 0)  ' Set Output Theoretical Values  = NONE
        retval = DmisCommand.SetToggleString (1, OUTPUT_FEAT_W_DIMENS, 0) ' Set Output Features with Dimensions  = NO
        retval = DmisCommand.SetToggleString (2, MODE_TYPE, 0)  ' Set Mode  = END
    
      ' Line for Excel / CSV file output
      ' note that not all excel settings can be set via basic/C++
        retval = DmisCommand.SetToggleString (1, OUTPUT_TO_REPORT, 0) ' Set Output To Excel  = OFF
        retval = DmisCommand.SetToggleString (3, UNIT_TYPE, 0)  ' Set File Print Method  = AUTO
        retval = DmisCommand.PutText ("1", ROW_ID, 0) ' Set Index Start  = 1
        retval = DmisCommand.SetToggleString (2, OUTPUT_TYPE, 0) ' Set Auto Open  = ON
    
    DmisPart.RefreshPart
    


    Code for CSV ONLY
    Set DmisCommand = DmisCommands.Add(PRINT_REPORT, TRUE)
    DmisCommand.Marked = TRUE
    
      ' Line for PDF file output
        retval = DmisCommand.SetToggleString (1, PRINT_TO_FILE, 0)   ' Set Print To File  = OFF
        retval = DmisCommand.PutText ("", FILE_NAME, 1) ' Set Filename Item 1 = ""
        retval = DmisCommand.SetToggleString (2, FILE_COMMAND_TYPE, 0)  ' Set File Print Method  = OVERWRITE
        retval = DmisCommand.SetToggleString (1, ONOFF_TYPE, 0) ' Set Auto Open  = OFF
    
      ' Line for Printer output
        retval = DmisCommand.SetToggleString (1, PRINT_TO_PRINTER, 0) ' Set Print To Printer  = OFF
        retval = DmisCommand.PutText ("1", INDEX_END, 0) ' Set Number Of Copies  = 1
        retval = DmisCommand.SetToggleString (1, PRINT_DELETE_RUNS, 0) ' Set Previous Runs  = DELETE_INSTANCES
    
      ' Line for *.dmo file output
        retval = DmisCommand.SetToggleString (1, OUTPUT_DMIS_REPORT, 0)  ' Set DMIS Output  = OFF
        retval = DmisCommand.SetToggleString (1, OVERWRITE, 0) ' Set Overwrite  = INDEX
        retval = DmisCommand.SetToggleString (1, OUTPUT_FEATURE_NOMS, 0) ' Set Output Theoretical Values  = NONE
        retval = DmisCommand.SetToggleString (1, OUTPUT_FEAT_W_DIMENS, 0) ' Set Output Features with Dimensions  = NO
        retval = DmisCommand.SetToggleString (2, MODE_TYPE, 0) ' Set Mode  = END
     
      ' Line for Excel / CSV file output
      ' note that not all excel settings can be set via basic/C++
        retval = DmisCommand.SetToggleString (2, OUTPUT_TO_REPORT, 0)  ' Set Output To Excel  = ON
        retval = DmisCommand.SetToggleString (3, UNIT_TYPE, 0) ' Set File Print Method  = AUTO
        retval = DmisCommand.PutText ("1", ROW_ID, 0) ' Set Index Start  = 1
        retval = DmisCommand.PutText ("C:\Users\QS\Desktop\MigrationsTools\test123.CSV", SUB_NAME, 1) <- Change CSV path here
        retval = DmisCommand.SetToggleString (2, OUTPUT_TYPE, 0) ' Set Auto Open  = ON
    
    DmisPart.RefreshPart
    


    CSV and PDF output can be combined in a single pcDMIS-print-command
    CSV and Excel output can not be combined, but aditional print commands maybe possible
Reply
  • Hello,


    "TO_FILE=" Line for PDF output
    -> "APPEND=" means he is trying to append the measurement data to an existing PDF file, is that intentional? If the path is wrong or the file doesn't exist, it simply doesn't do anything

    "TO_PRINTER=" he is trying to print to a real printer.

    "TO_DMIS_REPORT=" Line for *.dmo files -> "FILENAME=REPORT_NAME" in this line does nothing, because "TO_DMIS_REPORT=OFF"
    -> REPORT_NAME is a pcDMIS-Variable
    -> B is forum formating and can be deleted

    "TO_EXCEL=" Line for Excel and CSV output files

    ################################################## ####################################

    in your example it ONLY tries to attach the measurement data to a PDF called #1.pdf
    all other lines are =OFF

    if you keep assigning a new file (a new Number) name via your external program, then "OVERWRITE" is the correct procedure.
    File extension ".PDF" is not required
    File extension ".CSV" is required in Excel Line

    Code for PDF ONLY
    Set DmisCommand = DmisCommands.Add(PRINT_REPORT, TRUE)
    DmisCommand.Marked = TRUE
    
      ' Line for PDF-File output
        retval = DmisCommand.SetToggleString (2, PRINT_TO_FILE, 0) ' Set Print To File  = ON
        retval = DmisCommand.PutText ("C:\Users\QS\Desktop\MigrationsTools\test123", FILE_NAME, 1) '<- change PDF path here, ("test123" is indeed the filename)
        retval = DmisCommand.SetToggleString (2, FILE_COMMAND_TYPE, 0) ' Set File Print Method  = OVERWRITE
        retval = DmisCommand.SetToggleString (1, ONOFF_TYPE, 0)  ' Set Auto Open  = OFF
    
      ' Line for Printer output
        retval = DmisCommand.SetToggleString (1, PRINT_TO_PRINTER, 0) ' Set Print To Printer  = OFF
        retval = DmisCommand.PutText ("1", INDEX_END, 0)  ' Set Number Of Copies  = 1
        retval = DmisCommand.SetToggleString (1, PRINT_DELETE_RUNS, 0) ' Set Previous Runs  = DELETE_INSTANCES
    
      ' Line for *.dmo file output
        retval = DmisCommand.SetToggleString (1, OUTPUT_DMIS_REPORT, 0) ' Set DMIS Output  = OFF
        retval = DmisCommand.SetToggleString (1, OVERWRITE, 0)   ' Set Overwrite  = INDEX
        retval = DmisCommand.SetToggleString (1, OUTPUT_FEATURE_NOMS, 0)  ' Set Output Theoretical Values  = NONE
        retval = DmisCommand.SetToggleString (1, OUTPUT_FEAT_W_DIMENS, 0) ' Set Output Features with Dimensions  = NO
        retval = DmisCommand.SetToggleString (2, MODE_TYPE, 0)  ' Set Mode  = END
    
      ' Line for Excel / CSV file output
      ' note that not all excel settings can be set via basic/C++
        retval = DmisCommand.SetToggleString (1, OUTPUT_TO_REPORT, 0) ' Set Output To Excel  = OFF
        retval = DmisCommand.SetToggleString (3, UNIT_TYPE, 0)  ' Set File Print Method  = AUTO
        retval = DmisCommand.PutText ("1", ROW_ID, 0) ' Set Index Start  = 1
        retval = DmisCommand.SetToggleString (2, OUTPUT_TYPE, 0) ' Set Auto Open  = ON
    
    DmisPart.RefreshPart
    


    Code for CSV ONLY
    Set DmisCommand = DmisCommands.Add(PRINT_REPORT, TRUE)
    DmisCommand.Marked = TRUE
    
      ' Line for PDF file output
        retval = DmisCommand.SetToggleString (1, PRINT_TO_FILE, 0)   ' Set Print To File  = OFF
        retval = DmisCommand.PutText ("", FILE_NAME, 1) ' Set Filename Item 1 = ""
        retval = DmisCommand.SetToggleString (2, FILE_COMMAND_TYPE, 0)  ' Set File Print Method  = OVERWRITE
        retval = DmisCommand.SetToggleString (1, ONOFF_TYPE, 0) ' Set Auto Open  = OFF
    
      ' Line for Printer output
        retval = DmisCommand.SetToggleString (1, PRINT_TO_PRINTER, 0) ' Set Print To Printer  = OFF
        retval = DmisCommand.PutText ("1", INDEX_END, 0) ' Set Number Of Copies  = 1
        retval = DmisCommand.SetToggleString (1, PRINT_DELETE_RUNS, 0) ' Set Previous Runs  = DELETE_INSTANCES
    
      ' Line for *.dmo file output
        retval = DmisCommand.SetToggleString (1, OUTPUT_DMIS_REPORT, 0)  ' Set DMIS Output  = OFF
        retval = DmisCommand.SetToggleString (1, OVERWRITE, 0) ' Set Overwrite  = INDEX
        retval = DmisCommand.SetToggleString (1, OUTPUT_FEATURE_NOMS, 0) ' Set Output Theoretical Values  = NONE
        retval = DmisCommand.SetToggleString (1, OUTPUT_FEAT_W_DIMENS, 0) ' Set Output Features with Dimensions  = NO
        retval = DmisCommand.SetToggleString (2, MODE_TYPE, 0) ' Set Mode  = END
     
      ' Line for Excel / CSV file output
      ' note that not all excel settings can be set via basic/C++
        retval = DmisCommand.SetToggleString (2, OUTPUT_TO_REPORT, 0)  ' Set Output To Excel  = ON
        retval = DmisCommand.SetToggleString (3, UNIT_TYPE, 0) ' Set File Print Method  = AUTO
        retval = DmisCommand.PutText ("1", ROW_ID, 0) ' Set Index Start  = 1
        retval = DmisCommand.PutText ("C:\Users\QS\Desktop\MigrationsTools\test123.CSV", SUB_NAME, 1) <- Change CSV path here
        retval = DmisCommand.SetToggleString (2, OUTPUT_TYPE, 0) ' Set Auto Open  = ON
    
    DmisPart.RefreshPart
    


    CSV and PDF output can be combined in a single pcDMIS-print-command
    CSV and Excel output can not be combined, but aditional print commands maybe possible
Children
No Data