Close Vision Client Windows Using Shared Script

I was doing some searching and couldn't find a topic on this. Is it possible to close a Vision Client window using a shared script from another project? It looks like I have access to the Client Id and the Address. I was thinking I might be able to use them to achieve my goals. If so, can someone point me to some documentation or the right direction to go about this?

Thanks for the help!

It's a built in one-liner to exit a vision client system.util.exit() system.util.exit - Ignition User Manual 8.1 - Ignition Documentation

Don't know what your exact use case is. Are you trying to monitor live sessions and exit based on some criteria (like inactivity or something)?

@bkarabinchak.psi Thank you for the reply. But I am not trying to close the client. I would like to close a certain window that the client has open.

Ok, what is the criteria for closing that window?

That too is a built-in one liner system.nav.closeWindow('myWindowPath') system.nav.closeWindow - Ignition User Manual 8.1 - Ignition Documentation

What if there is more than one client that has that window open? How will it choose the correct client?

Well again what is the criteria to close this window? I'm wondering if you even need to use the gateway to manage this or if it can be done within a client timer script or similar. Then you would not need to worry about clientId's or sending messages between GW/client. But again, I don't know what your particulars are. What is the end goal? It's very possible this logic can be local to the window itself even.

Well it is actually based on when some tcp data is received from a connected device. I have a tag change script on a tag that is configured to watch the device. The script calls the shared script and I would like to close the window using that script.

1 Like

Ok, I assume this device is connected to your gateway already, it has something a tag showing the data, and from the data you receive in this you are able to tell which client to close? Are these assumptions correct?

Yes, the device is connected to the gateway already. I have access to the client id while in the shared script.

You already have a shared script that is managing this data/knows about clients? In that case, operating from a gateway scope, do a system.util.sendMessage() system.util.sendMessage - Ignition User Manual 8.1 - Ignition Documentation to the appropriate client with the String clientSessionId - Limits the message delivery to a client with the specified session ID. [optional] argument.

GW Side:

# Your logic to determine what client to close
clientToClose = 'someId'
system.util.sendMessage('someProject','closeSomeWindowMsg', scope='C', clientSessionId=clientToClose)

On the client side you will need to setup message handler, in this example called closeSomeWindowMsg to accept that message, and in that you should do something like

    # Window isn't open - except prevents an error popup

If it's not clear how to integrate with your existing script I think you will have to share your shared script.

Thank you for the help. I think is the right direction!

1 Like

An important point of clarification I want to underscore:
The 'project library' is just that - a library of scripts. Scripts in the project library have no inherent scope. They're just "library" functions that can be called from anywhere - the calling scope is what determines your execution environment. You can (and often will) write scopes that are agnostic to being called from the gateway or a Vision client, with the prominence of both Perspective and Vision.