Email bar chart?

I have a run time email report that I have ignition send out every week to the plant managers that tells them how many hours each robot cell ran for the week. I have been asked to include the bar chart from my project in the email. does anyone know if its possible to capture the bar chart and include it in an email or if there is a way to do a screen grab and include it in the email?

thank you

pretty sure you can do it but you would need to have a special client running all the time and write some scripting to startup at the specified time that first makes sure you have the latest data, then exports out the window, then creates and sends the email.

If you export out the chart to an image, you can attach the image when sending email (using gmail).
This code should do the trick:

from java.util import Date
from java.util import Calendar

cal = Calendar.getInstance()
todayDateStr = system.db.dateFormat(cal.getTime(), "MM/dd/yyyy")

filePath = "C:\\path\\to\\image\\imagename.png"

fileName = filePath.split("\\")[-1] # This gets the filename without the C:\folder stuff
fileData = fpmi.file.readFileAsBytes(filePath)

smtp = ""
sender = ""
subject = "Daily Email Report (" + todayDateStr + ")"
body = """
Report Data goes here

recipients = ["",""], sender, subject, body, 0, recipients, [fileName], [fileData], username=sender, password="gmailpassword")  

Well its been a year since I first posted this question and im back to trying to figure it out… I have the following code that works perfectly in the script playground. but when I use it in a gateway timer script it will not run. Im not finding anything in the log. Any ideas? thank you.

[code] import system
from javax.imageio import ImageIO
from import ByteArrayOutputStream

window = system.gui.getWindow(“Main Windows/Email Screens/Chart”)
image = window.rootContainer.getComponent(“Container”)
bufferedImg = system.print.createImage(image)
baos = ByteArrayOutputStream()
ImageIO.write(bufferedImg, “PNG”, baos)
fileData = baos.toByteArray()
fileName = “history.png”

recipients = [“”]

body = (“This is a run time report”, sender, subject, body, 0, recipients, [fileName], [fileData])


Gateway Timer Scripts run on the Gateway. Windows run in designers and clients but not in the Gateway. Functions like system.gui.getWindow will not work in Gateway Event Scripts.

You could use a Client Timer Script that runs this code in an open client somewhere.

Here’s a resource for debugging and testing Gateway Event Scripts: … nt-scripts


Are there any other ways to extract the chart image in the gateway? is this something that can be done if I were to upgrade to 7.7?

thank you.

As nmudge said gateway scripts run in the Ignition Gateway and components and windows are client scoped, this means that from your gateway script you will not have access to your bar chart.

To include your chart in the email as an you can use a client script instead of a gateway script, and make sure that a client is up and running when you need to send that email.

Or you can save a copy of that chart in a client script to a network location that the gateway can reach, then attach the previously saved image, to your email. The downside here is of course that the chart pictured is not the most up to date version.

Thank you, that’s what I did. I have a dedicated computer at my desk that gathers screen grabs for each chart.