Ignition 8.0 " Print Screen Button" script example

Is there an example that shows the method to print out a VISION display using a button script?

I found some old (2010) references but they don’t work in Ignition 8.0

obj = system.gui.getParentWindow(event) .parent
printJob = system.print.createPrintJob(obj)
printJob.showPrintDialog = 0
printJob.orientation = system.print.LANDSCAPE
printJob.print()

Thanks

I think you need you doing sstem.getParentWindow.parent is the issue. Whats the windows parent? You need to give it a component, and I’m not sure what class or object the parent of a window is but it’s definitely not a component.

Try following the second example in the documentation with your root container or just the window.

https://docs.inductiveautomation.com/display/DOC79/system.print.createPrintJob

I guess my confusion is the difference between “root container” and “The window that the button is on”

It’s complicated. Try this script on a button’s actionPerformed event:

current = event.source
hierarchy = [current]
while current.parent:
	current = current.parent
	if current in hierarchy:
		break
	else:
		hierarchy.insert(0, current)
for x in hierarchy:
	print x.getClass().canonicalName

In a v7.9 designer I get this:

com.inductiveautomation.ignition.designer.IgnitionDesigner
javax.swing.JRootPane
javax.swing.JLayeredPane
javax.swing.JPanel
com.jidesoft.swing.ContentContainer
com.jidesoft.action.MainContainer
javax.swing.JPanel
com.jidesoft.docking.DefaultDockingManager.MainPanel
com.jidesoft.docking.DefaultDockingManager.DockedHiddenSlidingContainer
javax.swing.JPanel
com.jidesoft.docking.ContainerContainer
com.jidesoft.docking.DockedFrameContainer
javax.swing.JPanel
com.jidesoft.docking.ContainerContainer
com.jidesoft.docking.ContainerContainer
com.jidesoft.docking.ContainerContainer
com.jidesoft.docking.Workspace
com.inductiveautomation.ignition.designer.WorkspaceManager
javax.swing.JPanel
com.inductiveautomation.factorypmi.designer.workspace.WindowWorkspace
com.inductiveautomation.ignition.designer.designable.DesignPanel
javax.swing.JViewport
com.inductiveautomation.ignition.designer.designable.DesignPanel.LayerParent
com.inductiveautomation.ignition.designer.designable.DesignPanel.DesignableContainerLayer
com.inductiveautomation.factorypmi.application.FPMIWindow
javax.swing.JRootPane
javax.swing.JLayeredPane
com.inductiveautomation.factorypmi.application.components.BasicContainer
com.inductiveautomation.factorypmi.application.components.PMIButton

Everything in that list is a “Component” as far as java is concerned. The “Root Container” is that BasicContainer on the second to last line. The window is three lines above that.

Thanks All.

This Worked

job = system.print.createPrintJob(event.source.parent.getComponent(‘Container’))
job.setShowPrintDialog(1)`
job.setPageHeight(3)
job.setPageWidth(5)
job.setMargins(5)
job.setOrientation(0)

job. print ()

1 Like

The original code works fine, just tested it. What error are you seeing?