# Automating Image Capture On Scheduled Script

**URL:** <https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [June 12, 2024, 5:17pm UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766 "2024-06-12T17:17:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![AydHA](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@AydHA](https://forum.inductiveautomation.com/u/AydHA)\
**Post date:** [June 12, 2024, 5:17pm UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766/1 "2024-06-12T17:17:52Z")

</div>

Currently, we have an image that is created when a button is pressed. This button takes a .jpg image of the parent of the button. This view of the popup window is then saved down a file path. This works.

I'm wanting to automate this, so that the image of this "parent" popup window is automatically saved in the file path by using a scheduled gateway script.

The parent window is down Vision\>Windows\>Popups\>Dashboard\>Root Container\>Button\_4, if that helps for the directory of the button component that has the below code.

The Script Path is down Scripting\>Project Library\>ImageScript. The "Scripting" and "Vision" are siblings at the top of the tree.

I'm fairly certain all that needs to be changed is the line 9&10 to get the correct file path when trying to run the script outside of the button component.

Code Below  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/2/52dd4c7501b24b5df63c00522274ab478421cd5f.png)

Again, I want this script to run on a scheduled Gateway Script.

The pathway is shown below.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/3/33b307d4930ee251dcf4058f80c1665e9914961a.png)

---

<div class="post-metadata">

**Author:** ![Steven\_Cheron](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@Steven\_Cheron](https://forum.inductiveautomation.com/u/Steven_Cheron)\
**Post date:** [June 12, 2024, 5:23pm UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766/2 "2024-06-12T17:23:16Z")

</div>

I think the best is to use a gateway event script to send a message.

Then the component to capture received this message and use the function and pass itself as a parameter. So, in the function you have the component for `system.print.createImage()`

---

<div class="post-metadata">

**Author:** ![AydHA](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@AydHA](https://forum.inductiveautomation.com/u/AydHA)\
**Post date:** [June 12, 2024, 5:25pm UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766/3 "2024-06-12T17:25:43Z")

</div>

That's the plan, to run it on a schedule. I am just having trouble accessing the popup window that I wish to take an the .jpg image of. The code given is from a button that takes an image of its parent.

---

<div class="post-metadata">

**Author:** ![Steven\_Cheron](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@Steven\_Cheron](https://forum.inductiveautomation.com/u/Steven_Cheron)\
**Post date:** [June 12, 2024, 5:32pm UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766/4 "2024-06-12T17:32:54Z")

</div>

Oh I didn't catch that you are on vision. My bad !

Maybe the schedule script can set a boolean memory tag to true.  
Then, on the component, bind this tag on a custom property.  
And then, use a property change script to call your function.

---

<div class="post-metadata">

**Author:** ![AydHA](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@AydHA](https://forum.inductiveautomation.com/u/AydHA)\
**Post date:** [June 12, 2024, 7:13pm UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766/5 "2024-06-12T19:13:06Z")

</div>

I haven't had any luck with this so far, been trying at it for a bit and still stuck.

---

<div class="post-metadata">

**Author:** ![Kevin\_Flener](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@Kevin\_Flener](https://forum.inductiveautomation.com/u/Kevin_Flener)\
**Post date:** [June 12, 2024, 7:19pm UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766/6 "2024-06-12T19:19:44Z")

</div>

Just a question as I'm new to scripting in general and still learning.

Shouldn't this have one more " \ " at the beginning of the rawPath?

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/a/7afcd4f576a9a5f725d11aa6c9d3fc502a2772e9.png)

---

<div class="post-metadata">

**Author:** ![AydHA](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@AydHA](https://forum.inductiveautomation.com/u/AydHA)\
**Post date:** [June 12, 2024, 7:32pm UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766/7 "2024-06-12T19:32:50Z")

</div>

It depends on how you're going to manipulate the rawPath, since I'm using "from [java.io](http://java.io) import File" for the FormattedPath the syntax on the [java.io](http://java.io) wiki wanted 3 for the start.

---

<div class="post-metadata">

**Author:** ![Steven\_Cheron](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@Steven\_Cheron](https://forum.inductiveautomation.com/u/Steven_Cheron)\
**Post date:** [June 12, 2024, 7:35pm UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766/8 "2024-06-12T19:35:06Z")

</div>

What's wrong ?

---

<div class="post-metadata">

**Author:** ![AydHA](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@AydHA](https://forum.inductiveautomation.com/u/AydHA)\
**Post date:** [June 12, 2024, 8:22pm UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766/9 "2024-06-12T20:22:53Z")

</div>

I was unable to implement the tag script to command the button to take the image.

---

<div class="post-metadata">

**Author:** ![Steven\_Cheron](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@Steven\_Cheron](https://forum.inductiveautomation.com/u/Steven_Cheron)\
**Post date:** [June 13, 2024, 12:50pm UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766/10 "2024-06-13T12:50:03Z")

</div>

Have you create a boolean memory tag ?

If yes, bind it on a custom property on your component.

Add a property change script on the component. Remind to filter this event, it will be called multple time on startup for example. You can filter with this

```Python
if event.propertyName == "custom.yourPropertyName":
    # call your function inside your gateway script
    yourScript(self)

```

Your script needs to accept a parameter like that

```Python
def yourScript(component):
    ...
    bufferedImage = system.print.createImage(component)
    ...

```

If you want you can check if a component is passed to your function to avoid errors with that

```Python
if component is None:
    return

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [June 16, 2024, 2:22am UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766/11 "2024-06-16T02:22:07Z")

</div>

> [@AydHA](#):
>
> so that the image of this "parent" popup window is automatically saved in the file path by using a scheduled gateway script.

You're wanting to fire a button in a Vision client from the gateway?

This sort of thing should be done directly in the client.

**Example:**  
Put the custom property directly on the button called 'time', and set its datatype to _date_:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/4/b45bd33f572b190f02699c78bd65a26af1194abc.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/5/a5986490cd52ac23da16e2dbe5384e1801227586.png)

Use an expression binding to change the custom property value every minute:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/e/de6a937fe07c9718aef3a2c669588b761966f1f4.png)

Create a custom method on the button called `saveParentImage`, give it a parameter called 'date', and put the image creation script there:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/e/1e4d8d56a1ebaec45f78cb690afff3d2f801e054.png)

```python
#def saveParentImage(self, date):
	from java.io import File
	from javax.imageio import ImageIO
	
	# Create a buffered image of the button's parent and save it
	new_filename = 'Second_Rejects_Date%sTime_%s' % (system.date.format(date, 'yy_MM_dd'), system.date.format(date, 'HH_mm'))
	bufferedImage = system.print.createImage(event.source.parent)
	path = File('/kim-file01/open/.../.../%s' % new_filename)
	ImageIO.write(bufferedImage , "jpg", path)

```

Then, use a property change script to trigger the image creation at a specific time:

```python
# Run script from the client every morning at 8am
if event.propertyName == 'time' and system.date.format(event.newValue, 'HH:mm') == '08:00':
	event.source.saveParentImage(event.newValue)

```

...and from the button's action performed event handler, call it this way:

```python
# save an image of the parent container using the time custom property to create the file name
event.source.saveParentImage(event.source.time)

```

---

<div class="post-metadata">

**Author:** ![AydHA](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@AydHA](https://forum.inductiveautomation.com/u/AydHA)\
**Post date:** [June 20, 2024, 3:15pm UTC](https://forum.inductiveautomation.com/t/automating-image-capture-on-scheduled-script/91766/12 "2024-06-20T15:15:20Z")

</div>

This worked for me doing it this way as a test. I ended up just making an HTML formatted email, since attachments cannot be sent on a gateway. However, this was able to automatically take the screenshots. I had set it up to run on a single device doing this.
