Printing Multiple Reports at Once

I have a button that will print the current report viewer, but I want to loop through and print all my reports with a single button push. This is what I’ve got currently without any luck. Thanks,

reports = ['Optimizer', 'PanelSaw', 'Router', 'LoadSheet']

for item in reports:

  system.report.executeAndDistribute(path=item, 
  project='CNCManagement',
  action='print', 
  actionSettings = {'copies':1})

Printing from the report viewer will use the client machine’s printer choices. Printing via executeAndDistribute() will use the gateway’s printer choices. You need to make sure your gateway has a printer configured, and that the gateway service has permission to use it.

I don’t know how to do that, is there a reference page you can link me to? thanks

Start either here, or if you must, here.

The latter is somewhat disruptive – you’ll want to backup your gateway if you go that route.

:smiling_imp:

1 Like

I really don’t understand the need for ubuntu?? I have a networked printer setup named ‘P1Engineer’ I added the printer name to the code


reports = ['Optimizer', 'PanelSaw', 'Router', 'LoadSheet']

for item in reports:

  system.report.executeAndDistribute(path=item, 
  project='CNCManagement',
  action='print', 
  actionSettings = {'primaryPrinterName':'P1Engineer','copies':1})  

but the script does nothing, or at least there is no queue generated for the printer. I figured you’d just add the printer in the ignition gateway somewhere.

That was my attempt at humor, since I avoid Windows like the plague. The point is that is an operating-system level task, not an Ignition task. You have to go to or remote into the gateway and configure the printer there. And then make sure the gateway service can print to it.

So, I tested your code, and it works fine. The printer needs to be accessible from wherever you run that script. If the printer is only accessible from the gateway, and you run that code in the designer or client, it wont print. If the name of the printer is spelled wrong, it won’t print, or even error.

I’m going to put the multiple reports on the back burner for just a bit and skip to printing a report while changing a parameter which is a tag. It says that the item isn’t serializable. I forced the item to be a string with str() and it worked but changed the tag to ‘Row:1 columns’

data = event.source.parent.getComponent('Dropdown').data
params = system.dataset.toPyDataSet(data)

for item in params:
 
 system.tag.write("CNC_Global/ReportStyle", item)
  

 reportViewer = event.source.parent.getComponent('Report Viewer')
 
 def finished():
    #We're simply printing the report here, but you could place any amount of work 
    #here that you want to execute once the new report has been generated
    reportViewer.print(None, 1)        
 
#We'll use this function to constantly check to see if the report has finished loading
 def waiting():
 
    #While we're waiting....
    while reportViewer.reportLoading:
        #...don't do anything, just keep checking
        pass       
     
    #Once we get to this point, the report has finished loading, so lets call finished()
    #Using invokeLater so we can finish up in the Event Dispatch Thread
    system.util.invokeLater(finished)
 
#Start the waiting process in an asynchronous thread.
 system.util.invokeAsynchronous(waiting)

For the multiple report printing I tried the code below, and it works but it prints the last report 4 times instead of one of each of the reports. any ideas??

reports = ['Optimizer', 'PanelSaw', 'Router', 'LoadSheet']

for item in reports:
 
 event.source.parent.getComponent('Report Viewer').reportPath = item

 reportViewer = event.source.parent.getComponent('Report Viewer')
 
 def finished():
    #We're simply printing the report here, but you could place any amount of work 
    #here that you want to execute once the new report has been generated
    reportViewer.print(None, 0)        
 
#We'll use this function to constantly check to see if the report has finished loading
 def waiting():
 
    #While we're waiting....
    while reportViewer.reportLoading:
        #...don't do anything, just keep checking
        pass       
     
    #Once we get to this point, the report has finished loading, so lets call finished()
    #Using invokeLater so we can finish up in the Event Dispatch Thread
    system.util.invokeLater(finished)
 
#Start the waiting process in an asynchronous thread.
 system.util.invokeAsynchronous(waiting)

I finally figured out what you meant. I felt really stupid once I did haha. I got it to print but it printed a bunch of one line pages of symbols. Any ideas on that?

Oops I think its the wrong printer driver

Just for reference in case someone else might try to do this. Below is my code to print out 4 reports at once, while looping the 4th report through several ‘style’ report parameters, while allowing the user to select the printer to print to from a dropdown menu.

[code]
reports = [‘Optimizer’, ‘PanelSaw’, ‘Router’, ‘LoadSheet’]

for item in reports:
if item == ‘LoadSheet’:
data = event.source.parent.getComponent(‘StyleDD’).data
styles = system.dataset.toPyDataSet(data)
for row in styles:
for value in row:
params = {‘Style’:value}
system.report.executeAndDistribute(path=item,
project=‘CNCManagement’,
parameters = params,
action=‘print’,
actionSettings = {‘primaryPrinterName’:event.source.parent.getComponent(‘PrinterSelect’).selectedStringValue,
‘copies’:1})

else:
system.report.executeAndDistribute(path=item,
project=‘CNCManagement’,
action=‘print’,
actionSettings = {‘primaryPrinterName’:event.source.parent.getComponent(‘PrinterSelect’).selectedStringValue,
‘copies’:1}) [/code]