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 don't know what I'm doing wrong still but this code isn't doing what I want it to. PCDMIS is still prompting me to change the file name and it's not even starting with the value I gave it. It's just using what was there last time. It's adding the print commands but they don't work as expected. I'm kind of pulling my hair out over here.

    This C#:
    var reportPath = $@"{REPORTS_DIRECTORY_PATH}\{programData.Customer}\{programData.InternalPartName}-{programData.Revision}\{programData.RawMaterialId}\#{programData.UnitNumber}";
    
                var commands = _pcdPartProgram.Commands;
                commands.InsertionPointAfter(commands.LastCommand);
    
                var command = commands.Add(PRINT_REPORT, true);
                command.Marked = true;
    
                // Line for PDF-File output
                command.SetToggleString(2, PRINT_TO_FILE, 0);// Set Print To File  = ON
                command.PutText(reportPath, FILE_NAME, 1); // change PDF path here
                command.SetToggleString(2, FILE_COMMAND_TYPE, 0);// Set File Print Method  = OVERWRITE
                command.SetToggleString(1, ONOFF_TYPE, 0); // Set Auto Open  = OFF
    
                // Line for Printer output
                command.SetToggleString(1, PRINT_TO_PRINTER, 0);// Set Print To Printer  = OFF
                command.PutText("1", INDEX_END, 0); // Set Number Of Copies  = 1
                command.SetToggleString(1, PRINT_DELETE_RUNS, 0);// Set Previous Runs  = DELETE_INSTANCES
    
                // Line for *.dmo file output
                command.SetToggleString(1, OUTPUT_DMIS_REPORT, 0);// Set DMIS Output  = OFF
                command.SetToggleString(1, OVERWRITE, 0);  // Set Overwrite  = INDEX
                command.SetToggleString(1, OUTPUT_FEATURE_NOMS, 0); // Set Output Theoretical Values  = NONE
                command.SetToggleString(1, OUTPUT_FEAT_W_DIMENS, 0);// Set Output Features with Dimensions  = NO
                command.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++
                command.SetToggleString(2, OUTPUT_TO_REPORT, 0);  // Set Output To Excel  = ON
                command.SetToggleString(3, UNIT_TYPE, 0); // Set File Print Method  = AUTO
                command.PutText($"{reportPath}.CSV", SUB_NAME, 1); // <- Change CSV path here
                command.SetToggleString(1, OUTPUT_TYPE, 0); // Set Auto Open  = ON
    
                _pcdPartProgram.RefreshPart();
                _pcdPartProgram.Save();
    


    Produces this program snippet:
    PRINT/REPORT,EXEC MODE=END,$
                  TO_FILE=ON,OVERWRITE=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=INDEX,FILENAME=[B]REPORT_NAME[/B],$
                  REPORT_THEORETICALS=NONE,REPORT_FEATURE_WITH_DIMENSIONS=NO,$
                  TO_EXCEL=ON,AUTO=1,FILENAME=G:\My Drive\My Folder\Customer Inspections\Reports\Customer\9-03\RM-51\#1.CSV,AUTO OPEN=OFF,$
                  PREVIOUS_RUNS=DELETE_INSTANCES
    

Reply
  • I don't know what I'm doing wrong still but this code isn't doing what I want it to. PCDMIS is still prompting me to change the file name and it's not even starting with the value I gave it. It's just using what was there last time. It's adding the print commands but they don't work as expected. I'm kind of pulling my hair out over here.

    This C#:
    var reportPath = $@"{REPORTS_DIRECTORY_PATH}\{programData.Customer}\{programData.InternalPartName}-{programData.Revision}\{programData.RawMaterialId}\#{programData.UnitNumber}";
    
                var commands = _pcdPartProgram.Commands;
                commands.InsertionPointAfter(commands.LastCommand);
    
                var command = commands.Add(PRINT_REPORT, true);
                command.Marked = true;
    
                // Line for PDF-File output
                command.SetToggleString(2, PRINT_TO_FILE, 0);// Set Print To File  = ON
                command.PutText(reportPath, FILE_NAME, 1); // change PDF path here
                command.SetToggleString(2, FILE_COMMAND_TYPE, 0);// Set File Print Method  = OVERWRITE
                command.SetToggleString(1, ONOFF_TYPE, 0); // Set Auto Open  = OFF
    
                // Line for Printer output
                command.SetToggleString(1, PRINT_TO_PRINTER, 0);// Set Print To Printer  = OFF
                command.PutText("1", INDEX_END, 0); // Set Number Of Copies  = 1
                command.SetToggleString(1, PRINT_DELETE_RUNS, 0);// Set Previous Runs  = DELETE_INSTANCES
    
                // Line for *.dmo file output
                command.SetToggleString(1, OUTPUT_DMIS_REPORT, 0);// Set DMIS Output  = OFF
                command.SetToggleString(1, OVERWRITE, 0);  // Set Overwrite  = INDEX
                command.SetToggleString(1, OUTPUT_FEATURE_NOMS, 0); // Set Output Theoretical Values  = NONE
                command.SetToggleString(1, OUTPUT_FEAT_W_DIMENS, 0);// Set Output Features with Dimensions  = NO
                command.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++
                command.SetToggleString(2, OUTPUT_TO_REPORT, 0);  // Set Output To Excel  = ON
                command.SetToggleString(3, UNIT_TYPE, 0); // Set File Print Method  = AUTO
                command.PutText($"{reportPath}.CSV", SUB_NAME, 1); // <- Change CSV path here
                command.SetToggleString(1, OUTPUT_TYPE, 0); // Set Auto Open  = ON
    
                _pcdPartProgram.RefreshPart();
                _pcdPartProgram.Save();
    


    Produces this program snippet:
    PRINT/REPORT,EXEC MODE=END,$
                  TO_FILE=ON,OVERWRITE=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=INDEX,FILENAME=[B]REPORT_NAME[/B],$
                  REPORT_THEORETICALS=NONE,REPORT_FEATURE_WITH_DIMENSIONS=NO,$
                  TO_EXCEL=ON,AUTO=1,FILENAME=G:\My Drive\My Folder\Customer Inspections\Reports\Customer\9-03\RM-51\#1.CSV,AUTO OPEN=OFF,$
                  PREVIOUS_RUNS=DELETE_INSTANCES
    

Children
No Data