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
  • A cut from it:


    RepWin.FullReportMode

    EditWin.SetPrintOptionsEx PCD_FILE,DMIS_OFF,PCD_OVERWRITE,0,Fullname,PCD_PDF,False

    RepWin.LoadReportTemplate "(path here...)\DefaultReportingTemplateBackup\TEXTONLY.RTP"
    RepWin.RefreshReport
    RepWin.PrintReport


    Fullname being the complete name of the new file.

    Removed the grossly long local path of the template, going to fix it so that it´s relative the PC-DMIS homedir...
  • Good lord that section of the automation language is not right!

    Buggy as ****, however this seems to work.

    I'm not sure why but it seems I need to refresh report twice (before and after setting the print options)

    Also (and I think this is what causes the appending, make sure you switch printing off again at the end)





    Sub main()

    Dim pcapp As Object
    Dim pcpart As Object
    Dim ew As Object
    Dim rw As Object

    Set pcapp = createobject("pcdlrn.application")
    Set pcpart = pcapp.activepartprogram


    Set rw = pcpart.reportwindow

    rw.FullReportMode

    rw.RefreshReport


    Set ew = pcpart.editwindow



    ew.SetPrintOptionsEx 2,0,3,0,"C:\Temp\Test123.pdf",1,0



    rw.RefreshReport

    rw.printreport

    ew.SetPrintOptionsEx 0,0,3,0,"C:\Temp\Test123.pdf",1,0

    End Sub
  • Yeah, seems to be a bit of a mess. :-/
    I'll try it out when I get back from the holidays.

    Thanks and merry Christmas!
    This seems to be a very helpful forum. I'll see if I can recipocate somehow. :-)
  • Yeah, seems to be a bit of a mess. :-/
    I'll try it out when I get back from the holidays.

    Thanks and merry Christmas!
    This seems to be a very helpful forum. I'll see if I can recipocate somehow. :-)



    That's the idea!
  • I tried it, sadly it didn´t work on my computer. Pasted the code and altered only the path. He still appends, and still adds index when switching from AUTO when AUTO has been set manually. (Unfortunately not a case I can simply avoid.)

    If it´s a error in automation, which seems to be the case, it could possibly be the same error as both problems seems related to the mode not being switched properly.

    I´ll look into it some more when I have more time.
  • 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
    
  • 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.
  • How We program the filename of Excel output Printer in PcDmis2014
  • Make sure you set: ReportWindow.ReportMode()

    It sounds like you are in Last Execution Mode, so when the PDF is overwritten it contains a report for each time the program was executed, making it appear to append to the PDF instead.