# How to take screenshots of your Ignition windows

**URL:** <https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863>\
**Category:** Ignition\
**Created:** [January 17, 2014, 6:06pm UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863 "2014-01-17T18:06:13Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [January 17, 2014, 6:06pm UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863/1 "2014-01-17T18:06:13Z")

</div>

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.

```auto
def takeScreenshot(twindow):
	from java.io 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);
	window.paint(bufferedImage.getGraphics());

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

```

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

```auto
from app.tech 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)
	time.sleep(2.5)
	takeScreenshot(row)
	system.nav.closeWindow(row)
system.nav.swapTo(currentWindow)
```

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

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [January 17, 2014, 9:18pm UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863/2 "2014-01-17T21:18:57Z")

</div>

Nice

---

<div class="post-metadata">

**Author:** ![haythem-khalfaoui](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@haythem-khalfaoui](https://forum.inductiveautomation.com/u/haythem-khalfaoui)\
**Post date:** [March 17, 2018, 5:33pm UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863/3 "2018-03-17T17:33:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mau89](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mau89/32/20680_2.png) [@Mau89](https://forum.inductiveautomation.com/u/Mau89)\
**Post date:** [April 18, 2018, 2:36pm UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863/4 "2018-04-18T14:36:35Z")

</div>

Thanks, good function

---

<div class="post-metadata">

**Author:** ![roizundak](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/roizundak/32/4430_2.png) [@roizundak](https://forum.inductiveautomation.com/u/roizundak)\
**Post date:** [August 1, 2018, 9:11am UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863/5 "2018-08-01T09:11:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 1, 2018, 12:19pm UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863/6 "2018-08-01T12:19:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BryanB](https://avatars.discourse-cdn.com/v4/letter/b/57b2e6/32.png) [@BryanB](https://forum.inductiveautomation.com/u/BryanB)\
**Post date:** [April 14, 2020, 12:12am UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863/7 "2020-04-14T00:12:56Z")

</div>

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?).

---

<div class="post-metadata">

**Author:** ![ryanjmclaughlin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryanjmclaughlin/32/4318_2.png) [@ryanjmclaughlin](https://forum.inductiveautomation.com/u/ryanjmclaughlin)\
**Post date:** [April 14, 2020, 7:41pm UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863/8 "2020-04-14T19:41:46Z")

</div>

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).

```auto
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 = ['somoeonethatcares@aol.com']

# Setup a filename and directory for the screenshot
dir = shared.util.selectDirectory('Select a directory to save screenshot...')
if dir is None:
	sys.exit()
filename = '%s_%s.jpg' % (system.date.format(system.date.now(), '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.tag.read('[System]Client/Network/Hostname').value
	ipAddress = system.tag.read('[System]Client/Network/IPAddress').value
	gatewayAddress = system.tag.read('[System]Client/Network/GatewayAddress').value

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

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

	# Construct the email body
	body = """
	<html>
	<body>
	<h2>
	<strong>%s User Screenshot</strong>
	</h2>
	<p>User Message: %s<strong></strong></p>
	<hr>
	<h2>
	<strong>Project Diags : %s</strong>
	</h2>
	<br>
	<h3>
	<strong>Network Diagnostics:</strong>
	</h3>
			 <br> System Hostname : %s
		 <br> IP Address : %s
		 <br> Gateway Address : %s
		 <br>
		 <br>
	<h3>
	<strong>System Diagnostics:</strong>
	</h3>
	<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
	<br>
	<br>
		<h3>
	<strong>User Diagnostics:</strong>
	</h3>
	<br> OS Username : %s
		<br> Client Username : %s
	<br>
	</body>
	</html> 
	""" % (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 = []
	try:
		contacts = system.user.getUser(system.tag.read('[System]Client/System/UserSource').value, username).getContactInfo()
		for contact in contacts:
			if contact.contactType == "email":
				if contact.value:
					cc.append(contact.value)
	except:
		pass
	
	# Send the email
	system.net.sendEmail(
		smtpProfile='default',
		subject='Screenshot | %s' % system.util.getProjectName(),
		body=body,
		html=True,
		to=emailTo,
		attachmentNames=attachmentNames,
		attachmentData=attachmentData,
		cc=cc
	)

```

---

<div class="post-metadata">

**Author:** ![j.abrante](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/j.abrante/32/10431_2.png) [@j.abrante](https://forum.inductiveautomation.com/u/j.abrante)\
**Post date:** [May 4, 2020, 11:08am UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863/9 "2020-05-04T11:08:57Z")

</div>

realy nice

---

<div class="post-metadata">

**Author:** ![lachguerabdallah](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lachguerabdallah/32/25558_2.png) [@lachguerabdallah](https://forum.inductiveautomation.com/u/lachguerabdallah)\
**Post date:** [October 8, 2020, 12:34pm UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863/10 "2020-10-08T12:34:05Z")

</div>

> [@ryanjmclaughlin](#):
>
> shared

i have this error:  
NameError: name 'shared' is not defined

---

<div class="post-metadata">

**Author:** ![ryanjmclaughlin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryanjmclaughlin/32/4318_2.png) [@ryanjmclaughlin](https://forum.inductiveautomation.com/u/ryanjmclaughlin)\
**Post date:** [October 8, 2020, 1:30pm UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863/11 "2020-10-08T13:30:48Z")

</div>

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.

```auto
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.
	
	parameters:
		-[startingPath] : Optional. Path to starting directory. Cannot contain symbolic links.
		-[title] : Optional. Title for dialog window.
		
	output:
		-path : The full path to the selected directory. None if user cancels the file selection.
	"""
	
	from javax.swing import JFileChooser
	from java.io import File
	import os.path
	
	if not startingPath == None:
		path = startingPath
	else:
		user = system.tag.read('[System]Client/User/HomeFolder').value
		path = os.path.join(user, 'Documents')
	
	chooser = JFileChooser()
	chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
	chooser.setAcceptAllFileFilterUsed(True)
	chooser.resetChoosableFileFilters()
	chooser.setDialogTitle(title)
	chooser.setCurrentDirectory(File(path))
	
	if chooser.showOpenDialog(None) == JFileChooser.APPROVE_OPTION:
		path = str(chooser.getSelectedFile()).replace('\\', '/')
	else:
		path = None
	return path

```

---

<div class="post-metadata">

**Author:** ![lachguerabdallah](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lachguerabdallah/32/25558_2.png) [@lachguerabdallah](https://forum.inductiveautomation.com/u/lachguerabdallah)\
**Post date:** [October 8, 2020, 1:35pm UTC](https://forum.inductiveautomation.com/t/how-to-take-screenshots-of-your-ignition-windows/7863/12 "2020-10-08T13:35:14Z")

</div>

I used;

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

thakns you
