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


  • I am able to get it to print pdfs without prompting the user but it won't save it in the file location that I am giving it. The only thing I have noticed is that I can't figure out how to change this feature
    DELETE_INSTANCES


    C#

    var reportPath = $@"{REPORTS_DIRECTORY_PATH}\{programData.Customer}\{programData.InternalPartName}-{programData.Revision}\{programData.RawMaterialId}\#{programData.UnitNumber}";
    
                //reportPath = reportPath.Replace(@"\", @"\\");
    
                var commands = _pcdPartProgram.Commands;
                commands.InsertionPointAfter(commands.LastCommand);
    
                //var command = commands.Add(ASSIGNMENT, true);
                //command.PutText("PDF_REPORT_NAME", DEST_EXPR, 0);
                //command.PutText($"\"{reportPath}.PDF\"", SRC_EXPR, 0);
    
                var command = commands.Add(PRINT_REPORT, true);
                command.Marked = true;
    
                // Set Print To File  = ON
                command.SetToggleString(2, PRINT_TO_FILE, 0);
    
                command.PutText($"{reportPath}", FILE_NAME, 1);
                //// index start
                //command.PutText("1", INDEX_START, 0);
    
                // Set File Print Method  = AUTO
                command.SetToggleString(2, FILE_COMMAND_TYPE, 0);
                // Set Auto Open  = OFF
                command.SetToggleString(1, ONOFF_TYPE, 0);
                // Set Print To Printer  = OFF
                command.SetToggleString(1, PRINT_TO_PRINTER, 0);
                // Set Number Of Copies  = 1
                command.PutText("1", INDEX_END, 0);
                // Set Previous Runs  = DELETE_INSTANCES
                command.SetToggleString(1, PRINT_DELETE_RUNS, 0);
                // Set DMIS Output  = OFF
                command.SetToggleString(1, OUTPUT_DMIS_REPORT, 0);
                // Set Overwrite  = OVERWRITE
                command.SetToggleString(2, OVERWRITE, 0);
                // Set Output Theoretical Values  = NONE
                command.SetToggleString(1, OUTPUT_FEATURE_NOMS, 0);
                // Set Output Features with Dimensions  = NO
                command.SetToggleString(1, OUTPUT_FEAT_W_DIMENS, 0);
                // Set Mode  = END
                command.SetToggleString(2, MODE_TYPE, 0);
                // Set Output To Excel  = ON
                command.SetToggleString(1, OUTPUT_TO_REPORT, 0);
                // Set File Print Method  = OVERWRITE
                command.SetToggleString(2, UNIT_TYPE, 0);
                // Set Auto Open  = OFF
                command.SetToggleString(1, OUTPUT_TYPE, 0);
    


    SCRIPT:
    PRINT/REPORT,EXEC MODE=END,$
                  TO_FILE=ON,APPEND=G:\My Drive\My Folder\Customer Inspections\Reports\Customer\9-03\RM-51\#1.PDF,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=DELETE_INSTANCES
    


    I have literally spent all day tinkering with this code and cannot get it to work. This feels insanely complicated for something that seems like it should be easy. Can anyone see what the heck I'm doing wrong?
Reply


  • I am able to get it to print pdfs without prompting the user but it won't save it in the file location that I am giving it. The only thing I have noticed is that I can't figure out how to change this feature
    DELETE_INSTANCES


    C#

    var reportPath = $@"{REPORTS_DIRECTORY_PATH}\{programData.Customer}\{programData.InternalPartName}-{programData.Revision}\{programData.RawMaterialId}\#{programData.UnitNumber}";
    
                //reportPath = reportPath.Replace(@"\", @"\\");
    
                var commands = _pcdPartProgram.Commands;
                commands.InsertionPointAfter(commands.LastCommand);
    
                //var command = commands.Add(ASSIGNMENT, true);
                //command.PutText("PDF_REPORT_NAME", DEST_EXPR, 0);
                //command.PutText($"\"{reportPath}.PDF\"", SRC_EXPR, 0);
    
                var command = commands.Add(PRINT_REPORT, true);
                command.Marked = true;
    
                // Set Print To File  = ON
                command.SetToggleString(2, PRINT_TO_FILE, 0);
    
                command.PutText($"{reportPath}", FILE_NAME, 1);
                //// index start
                //command.PutText("1", INDEX_START, 0);
    
                // Set File Print Method  = AUTO
                command.SetToggleString(2, FILE_COMMAND_TYPE, 0);
                // Set Auto Open  = OFF
                command.SetToggleString(1, ONOFF_TYPE, 0);
                // Set Print To Printer  = OFF
                command.SetToggleString(1, PRINT_TO_PRINTER, 0);
                // Set Number Of Copies  = 1
                command.PutText("1", INDEX_END, 0);
                // Set Previous Runs  = DELETE_INSTANCES
                command.SetToggleString(1, PRINT_DELETE_RUNS, 0);
                // Set DMIS Output  = OFF
                command.SetToggleString(1, OUTPUT_DMIS_REPORT, 0);
                // Set Overwrite  = OVERWRITE
                command.SetToggleString(2, OVERWRITE, 0);
                // Set Output Theoretical Values  = NONE
                command.SetToggleString(1, OUTPUT_FEATURE_NOMS, 0);
                // Set Output Features with Dimensions  = NO
                command.SetToggleString(1, OUTPUT_FEAT_W_DIMENS, 0);
                // Set Mode  = END
                command.SetToggleString(2, MODE_TYPE, 0);
                // Set Output To Excel  = ON
                command.SetToggleString(1, OUTPUT_TO_REPORT, 0);
                // Set File Print Method  = OVERWRITE
                command.SetToggleString(2, UNIT_TYPE, 0);
                // Set Auto Open  = OFF
                command.SetToggleString(1, OUTPUT_TYPE, 0);
    


    SCRIPT:
    PRINT/REPORT,EXEC MODE=END,$
                  TO_FILE=ON,APPEND=G:\My Drive\My Folder\Customer Inspections\Reports\Customer\9-03\RM-51\#1.PDF,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=DELETE_INSTANCES
    


    I have literally spent all day tinkering with this code and cannot get it to work. This feels insanely complicated for something that seems like it should be easy. Can anyone see what the heck I'm doing wrong?
Children
No Data