Automating Image Capture On Scheduled Script

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

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

The pathway is shown below.

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

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.

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.

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

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

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

What's wrong ?

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

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

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

Your script needs to accept a parameter like that

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

if component is None:
    return

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
image

Use an expression binding to change the custom property value every minute:
image

Create a custom method on the button called saveParentImage, give it a parameter called 'date', and put the image creation script there:
image

#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:

# 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:

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

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.

1 Like