# Screenshot Using Robot().CreateScreenCapture

**URL:** <https://forum.inductiveautomation.com/t/screenshot-using-robot-createscreencapture/116401>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [July 14, 2026, 4:35pm UTC](https://forum.inductiveautomation.com/t/screenshot-using-robot-createscreencapture/116401 "2026-07-14T16:35:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ttoth](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@ttoth](https://forum.inductiveautomation.com/u/ttoth)\
**Post date:** [July 14, 2026, 4:35pm UTC](https://forum.inductiveautomation.com/t/screenshot-using-robot-createscreencapture/116401/1 "2026-07-14T16:35:21Z")

</div>

Using ignition 8.1.27 vision

I have a button that creates a screenshot of the open program. I recently changed the entire script from a project script that created a PDF by sending the image through SQL to a button script that makes a JPEG instead using the following code:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/4/04ced0ddec0a5723d988c6867d17eb61231f4837.png)

The old way of sending the image through SQL was causing temporary communication losses with the client/gateway. I thought the changes I made would stop this but it seems I still have comm losses. When I tried to change the button script to a gateway project script it works the first time the button is pressed, then it stops working until the program is closed/ reopened. It seems to work back to back as a button script - but will eventually cause comm loss. Am I missing something to close out the image once created? I know that in both scenarios (project script or button script) the code is reaching the end because the last line creates an event log that I can see, but with the project script it won't execute after the first time

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [July 14, 2026, 4:43pm UTC](https://forum.inductiveautomation.com/t/screenshot-using-robot-createscreencapture/116401/2 "2026-07-14T16:43:50Z")

</div>

It looks like you have cut off part of your code at the bottom, post code, not pictures of code. Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

Other points of note:  
-This doesn't appear to be a project library script, as I'm not seeing any function `def` anywhere.  
-Don't use `exit()`, full stop. If you need to exit your logic early, put your logic in a function in the project library and use `return`. Call said function from your button.  
-Ignition provides built in methods for both reading and writing to files. Use `system.file.writeFile` instead of `ImageIO.write`.  
-In general, use built in Ignition methods before deferring to java or python packages (especially with times/dates).

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 14, 2026, 4:45pm UTC](https://forum.inductiveautomation.com/t/screenshot-using-robot-createscreencapture/116401/3 "2026-07-14T16:45:02Z")

</div>

Project scripts only ever run once (per project save/update). You should be defining **constants** in the project library plus **functions** that do the actual work. Your event should call a function in the library script.
