Bypassing Overwrite Message

My customer has an existing HMI which his IT guy is printing a Screen from the HMI every thirty seconds and saving it to a Cloud server as a .JPG. His end users are than able to view these .JPG’s on a web page without compromising his internets bandwidth. I am in the process of upgrading his HMI to Ignition and am looking at doing pretty much the same thing, but I am stuck. Here’s where I’m at:

I am using a script from a simple pushbutton to test. My script is as followed:

path = “C:\ktwd\Screen1.jpg”
system.print.printToImage(event.source.parent, path)

Works great, but my end product will be a gateway script happening every thirty seconds, which is where my problem is. If I push this pushbutton again I get the “Overwrite File?” box. I need to overwrite this file automatically without answering this message.

Any thoughts. I have dug through all the scripting functions and cannot find anything that would allow me to delete “C:\ktwd\Sceen1.jpg” than save “C:\ktwd\Sceen1.jpg”

This isn’t going to work in a gateway script - there won’t be any screen to print.

You’ll have to use system.print.createImage to create a BufferedImage object, then get the binary data from it and use system.file.writeFile to actually save it to disk - since writeFile overwrites by default.

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

image = system.print.createImage(event.source.parent.getComponent(‘Chart’))
baos = ByteArrayOutputStream()
ImageIO.write(image, “png”, baos)
imageInByte = baos.toByteArray()

system.file.writeFile(r"C:\Users\pgriffith\Documents\Test.png", imageInByte)

Where is the BufferedImage stored?