Does anyone know a way to print multiple windows or more preferably create a PDF (snapshot) of multiple windows of a client? The goal is to create a snapshot of all the windows in the project
Iterating through your list of windows, you will need to open them (most likely with some appropriate parameters to avoid any red overlays) using system.nav.openWindow(windowName).
Then you need to get and feed the the root container of the window to your system.print.createPrintJob with all the settings and then print it.
You will probably need a pause in between doing each of these. I know time.sleep. is frowned upon (sorry Phil!) but this sounds like a one-shot operation so for the sake of being able to give you an answer that works, I would use it for now.
All together I think it would look like
allWindows = system.gui.getWindowNames() # Or hardcode your list if you only need a subset
for window in allWindows:
win = system.nav.openWindow(window)
rc = win.getRootContainer()
# from here we can use your script
job = system.print.createPrintJob(rc)
job.setMargins(0.5)
job.fitToPage = 1
job.orientation = system.print.LANDSCAPE
job.showPageFormat = 0
job.print()
time.sleep(10)
Only catch I can think is some windows are needed and some are now in which case I would include a variable that is a dictionary of your window names and desired parameters. In that case you can do something like
allWindows = system.gui.getWindowNames() # Or hardcode your list if you only need a subset
windowParams = {'someWindow':{'someParam':'someValue'}}
for window in allWindows:
try:
params = windowParams[window]
except KeyError:
params={}
win = system.nav.openWindow(window, params)
rc = win.getRootContainer()
# from here we can use your script
job = system.print.createPrintJob(rc)
job.setMargins(0.5)
job.fitToPage = 1
job.orientation = system.print.LANDSCAPE
job.showPageFormat = 0
job.print()
time.sleep(10)
I have not tested this at all but I think this should be ok and the structure is basically right. You may need to adjust the sleep depending on how quickly or slowly your windows load. Realistically if this is something you run often you probably want to use something other than time.sleep.
You can do this via direct access to Java's print system, to create a multi-page single job. IA's script function is a wrapper for a single component or window.
When working directly with printing operations, the windows do not need to be "on top", just open.
This is Vision. sleep() will hog the UI thread and your windows won't be able to open. Open them all without delay, then use .invokeLater() to run the function that actually prints.
When I do my testing with scripts and I need to do a rc=win.getRootContainer() in designer in script console to poke around a window, it does need to be be open which I use system.nav.openWindow() for in my own scripts to make it work. So I just assumed similar.
Pssst! @bkarabinchak.psi ! Whenever (almost) you think to use .sleep(), you are screwing up. Especially in Vision. Apologizing to me doesn't fix it. Apologize to those who get in a bind by taking that advice.
I still use it in the occasional one shot functions that is what this sounded like and in occasional uses hasn't ruined the overall functionality of the script so I didn't have reason to think so here. But I guess that's why you get a personal shoutout at ICC and I don't
This is what we have so far but it appears to give a print pop up for every window (Versus 1 popup that allows to save as one PDF.
Would also like to specify a subset of windows vs all if possible.
import system
allWindows = system.gui.getWindowNames()
for window in allWindows:
win = system.nav.openWindow(window)
rc = win.getRootContainer()
# from here we can use your script
job = system.print.createPrintJob(rc)
job.setMargins(0.5)
job.fitToPage = 1
job.orientation = system.print.LANDSCAPE
job.showPageFormat = 0
printjob = job.print()
system.util.invokeLater(printjob)
This can only do one window or component at a time. I solved this back in the FactoryPMI days to do custom multipage "reports". Buried somewhere in my archives. But I think I started here: