How to take screenshots of your Ignition windows

We have a client who wanted to get a screenshot of a whole bunch of windows. We decided to write a script to do this.

Define this function in your app scripts.

def takeScreenshot(twindow):
	from import File
	from java.awt.image import BufferedImage
	from javax.imageio import ImageIO
	import system
	home = system.util.getProperty("user.home")
	window = system.gui.getWindow(twindow)
	rec = window.getBounds();
	bufferedImage = BufferedImage(rec.width, rec.height,BufferedImage.TYPE_INT_ARGB);

	temp = File(home + "/Documents/screenshots/" + twindow + ".png");
	ImageIO.write(bufferedImage, "png", temp);

Then, define this script somewhere the user can access it. We usually put it in a client menu script

from import takeScreenshot
import time
currentWindow = system.tag.getTagValue("[System]Client\User\CurrentWindow")

windows = ["Put","Some","Windows","Here"]

for row in windows:
	obj = system.nav.openWindow(row)

The time.sleep code is only to allow the window to populate its bindings. You may need the increase the length of this delay.



I want to make a screenshot but for windows that are not open, it is not possible with getWindows (), the objective of this script is to see the window before opening it. Can you help me please


Thanks, good function

Getting This error:
File “”, line 11
temp = File(home + “/Documents/screenshots/” + twindow + “.png”);
IndentationError: unindent does not match any outer indentation level

Consistent indentation is very important in python. You can use tabs to indent, you can use space to indent, but you can’t mix them in the same block.

1 Like

Is there a good way to get a screenshot of everything that visible on the screen? For example, we’d like to include a header bar in the screenshot as well. The script in the original post uses the “.paint” on the window pyobject (is there a good place to find documentation for that?).

We have a shared template we drop on the header of all our Vision apps. When you click, in the actionPerfomed script we run the following that captures the screenshot and prompts the user to email the Ignition developers a copy (with the user automatically copied).

import os.path, sys
from java.awt import Window
from javax.swing import SwingUtilities

# Get the containing Swing container for Igniton
window = SwingUtilities.getAncestorOfClass(Window, event.source)

# Setup the To email addresses for the Screenshot
emailTo = ['']

# Setup a filename and directory for the screenshot
dir = shared.util.selectDirectory('Select a directory to save screenshot...')
if dir is None:
filename = '%s_%s.jpg' % (, 'yyyyMMdd_HHmmss'), system.util.getProjectName())
file = os.path.join(dir, filename)

# Generate and save the screenshot
system.print.printToImage(window, file)

# Prompt the user to email the screenshot
if system.gui.confirm('<html>A screenshot has been saved to <strong>%s</strong>. <br><br>Do you want to email a copy to the Ignition Application team?' % file, 'Email Screenshot'):

	# Setup the attachment
	attachmentNames = [filename]
	attachmentData = [system.file.readFileAsBytes(file)]
	# Prompt the user to add a message
	msg = system.gui.inputBox('A screenshot of the application has been captued and will be sent to the Ignition developers.  Please enter a short message with any details you wish to provide.', '')
	#Read network diag info
	hostname ='[System]Client/Network/Hostname').value
	ipAddress ='[System]Client/Network/IPAddress').value
	gatewayAddress ='[System]Client/Network/GatewayAddress').value

	#Read system diag info
	now =
	editCount ='[System]Client/System/EditCount').value
	fpmiVersion ='[System]Client/System/FPMIVersion').value
	javaVersion ='[System]Client/System/JavaVersion').value
	os ='[System]Client/System/OperatingSystem').value
	systemFlags ='[System]Client/System/SystemFlags').value

	#Read user diag info
	osUser ='[System]Client/User/OSUsername').value
	username ='[System]Client/User/Username').value

	# Construct the email body
	body = """
	<strong>%s User Screenshot</strong>
	<p>User Message: %s<strong></strong></p>
	<strong>Project Diags : %s</strong>
	<strong>Network Diagnostics:</strong>
			 <br> System Hostname : %s
		 <br> IP Address : %s
		 <br> Gateway Address : %s
	<strong>System Diagnostics:</strong>
	<br> Current Date/Time : %s
	<br> Edit Count : %s
	<br> FPMI Version : %s
	<br> Java Version : %s
	<br> Operating System : %s
	<br> System Flags : %s
	<strong>User Diagnostics:</strong>
	<br> OS Username : %s
		<br> Client Username : %s
	""" % (system.util.getProjectName(), msg, system.util.getProjectName(), hostname, ipAddress, gatewayAddress, now, editCount, fpmiVersion, javaVersion, os, systemFlags, osUser, username)
	# CC The source user if they have email setup
	cc = []
		contacts = system.user.getUser('[System]Client/System/UserSource').value, username).getContactInfo()
		for contact in contacts:
			if contact.contactType == "email":
				if contact.value:
	# Send the email
		subject='Screenshot | %s' % system.util.getProjectName(),

realy nice

i have this error:
NameError: name ‘shared’ is not defined

That’s a function we wrote to select a dir only as the built in system function has you select a file name. Personal preference of how you want to build it. This is just an example. Here is the selectDirectory function if you want to use it.

def selectDirectory(title='Select Folder', startingPath=None):
	Directory Selection Dialog
	Allows user selection of a directory, and returns the path to the selected directory.
	Utilizes Java Swing JFileChooser dialog window.
		-[startingPath] : Optional. Path to starting directory.  Cannot contain symbolic links.
		-[title] : Optional.  Title for dialog window.
		-path : The full path to the selected directory.  None if user cancels the file selection.
	from javax.swing import JFileChooser
	from import File
	import os.path
	if not startingPath == None:
		path = startingPath
		user ='[System]Client/User/HomeFolder').value
		path = os.path.join(user, 'Documents')
	chooser = JFileChooser()
	if chooser.showOpenDialog(None) == JFileChooser.APPROVE_OPTION:
		path = str(chooser.getSelectedFile()).replace('\\', '/')
		path = None
	return path

I used;

filename = system.file.saveFile(“myscreenshot”+".jpg")

thakns you