hexagon logo

Printreport

Hi!
Working on a little script to print pdf-reports. Is working well enough most of the time. One exception being that when ran multiple times the reports get appended to the existing file.

I use SetPrinterOptionsEx to set path and settings, using PCD_OVERWRITE as filemode. I print using the PrintReport method. Still it always gets appended. I've tried all the modes but it always appends.

Also when switching from for instance AUTO to OVERWRITE using the script it is changed correspondingly in the settings in the menu, however its still printed with the add indexnumbers from AUTO. I have to manually change it in the menu to something other than OVERWRITE and then back for the indexnumbers to go away.

First question, does printreport always use APPEND?

Second, why isn´t the printer settings updated properly by a call to SetPrinterEx? Do I need to do something else?

Is the any other way of doing this?

I guess I should be able to check if the file exists and delete before Printing, and check if the filename is wrong afterwards (due to switch from auto) and rename the file if needed. I would however really prefer not to if possible as it opens the possibilities of IO-exceptions...

Grateful for any input.
/L
Parents
  • Sounds like a bug. At least the Auto & Append part. I imagine things get confusing inside pcdmis since I'm guessing you are executing when this is being done.

    You define a global output definition - EditWin.SetPrintOptionsEx - defining you want some output.
    You switch the report from Execute Mode to FullReportMode (basically learn mode).
    And then switch or tell pcdmis to use/reuse the report using a template (RepWin.LoadReportTemplate). This alone should refresh the report.
    Then tell the report to print.
    At end of execution, since you defined you want output (see EditWin.SetPrintOptionsEx above), pcdmis will generate another report - perhaps this is where the extra report is coming from. You should turn the output off (as mentioned by Ninja above) after forcing the print.

    Automation report printing seems to be incomplete. Pcdmis goes through report finishing when execute is done. I'm guessing this is not being performed when forcing a print via automation before pcdmis is really done with execution. This probably explains why you switch to FullReportMode.



    You could probably get rid of the Auto index issue by defining an overwrite output in file output dialog. Just to define its not an auto index. Close the dialog, open the dialog and turn off output but keep the Overwrite.
    Save the part program.
    You will also need to turn off the end of execution printing after you print (see Ninja code above).

    Dim DmisApp As Object
    Dim DmisPart As Object
    Dim EditWindow As Object
    Dim ReportWindow As Object
    
    Sub Main
      Set DmisApp = CreateObject("PCDLRN.Application")
      Set DmisPart = DmisApp.ActivePartProgram
      Set EditWindow = DmisPart.EditWindow
      Set ReportWindow = DmisPart.ReportWindow
    
    EditWindow.SetPrintOptionsEx PCD_FILE, DMIS_OFF, PCD_OVERWRITE,  0,  "e:\ProblemReports\AutomationOutput.PDF", PCD_PDF, False
    ReportWindow.PrintReport
    EditWindow.SetPrintOptionsEx 0, DMIS_OFF, PCD_OVERWRITE,  0,  "e:\ProblemReports\AutomationOutput.PDF", PCD_PDF, False
    
    Set ReportWindow = Nothing
    Set EditWindow = Nothing
    Set DmisPart = Nothing
    Set DmisApp = Nothing
      
    End Sub
    


    Right now I'm just executing the script manually, no need to make things more complicated atm. Slight smile I don´t get two outputs right away, but if I run the script twice he will append to the old pdf, seemingly regardless of setting. Setting it to Overwrite makes no difference.

    I can get rid of the index as you say by manually changing the settings using the menu, but I can´t assume that no program will ever be set to Auto upon opening. It has to work regardless of starting state, and without forcing the user to make manuell changes.

    I may have to do some IO it seems... Hopefully that is less buggy.
Reply
  • Sounds like a bug. At least the Auto & Append part. I imagine things get confusing inside pcdmis since I'm guessing you are executing when this is being done.

    You define a global output definition - EditWin.SetPrintOptionsEx - defining you want some output.
    You switch the report from Execute Mode to FullReportMode (basically learn mode).
    And then switch or tell pcdmis to use/reuse the report using a template (RepWin.LoadReportTemplate). This alone should refresh the report.
    Then tell the report to print.
    At end of execution, since you defined you want output (see EditWin.SetPrintOptionsEx above), pcdmis will generate another report - perhaps this is where the extra report is coming from. You should turn the output off (as mentioned by Ninja above) after forcing the print.

    Automation report printing seems to be incomplete. Pcdmis goes through report finishing when execute is done. I'm guessing this is not being performed when forcing a print via automation before pcdmis is really done with execution. This probably explains why you switch to FullReportMode.



    You could probably get rid of the Auto index issue by defining an overwrite output in file output dialog. Just to define its not an auto index. Close the dialog, open the dialog and turn off output but keep the Overwrite.
    Save the part program.
    You will also need to turn off the end of execution printing after you print (see Ninja code above).

    Dim DmisApp As Object
    Dim DmisPart As Object
    Dim EditWindow As Object
    Dim ReportWindow As Object
    
    Sub Main
      Set DmisApp = CreateObject("PCDLRN.Application")
      Set DmisPart = DmisApp.ActivePartProgram
      Set EditWindow = DmisPart.EditWindow
      Set ReportWindow = DmisPart.ReportWindow
    
    EditWindow.SetPrintOptionsEx PCD_FILE, DMIS_OFF, PCD_OVERWRITE,  0,  "e:\ProblemReports\AutomationOutput.PDF", PCD_PDF, False
    ReportWindow.PrintReport
    EditWindow.SetPrintOptionsEx 0, DMIS_OFF, PCD_OVERWRITE,  0,  "e:\ProblemReports\AutomationOutput.PDF", PCD_PDF, False
    
    Set ReportWindow = Nothing
    Set EditWindow = Nothing
    Set DmisPart = Nothing
    Set DmisApp = Nothing
      
    End Sub
    


    Right now I'm just executing the script manually, no need to make things more complicated atm. Slight smile I don´t get two outputs right away, but if I run the script twice he will append to the old pdf, seemingly regardless of setting. Setting it to Overwrite makes no difference.

    I can get rid of the index as you say by manually changing the settings using the menu, but I can´t assume that no program will ever be set to Auto upon opening. It has to work regardless of starting state, and without forcing the user to make manuell changes.

    I may have to do some IO it seems... Hopefully that is less buggy.
Children
No Data