Detect vision or perspective

Ignition v8.1.

Is there a way to determine if a script is running in a vision session or a perspective session?

Scripts are either run in the client scope or the gateway scope. For perspective, all scripts are executed on the gateway. In vision, some are executed on the client side. Here is an example of detected which scope you are in:

def getScope():
	"""gets the scope that the execution is running in and returns a string indication of which scope
	
		Returns: a string indicating with scope the function is executing in
	"""
	from com.inductiveautomation.ignition.common.model import ApplicationScope
	scope = ApplicationScope.getGlobalScope()
	
	if ApplicationScope.isGateway(scope):
		return 'gateway'
	if ApplicationScope.isClient(scope):
		return 'client'
	if ApplicationScope.isDesigner(scope):
		return 'designer'

Yep I’m aware of perspective on the gateway.

However, if a script is called via a Gateway Event then it is running on the gateway, but it isn’t Perspective.

I’m trying to create a common exception handling system that will be able to be used for both vision and perspective to show popups or docks depending on where it was called.

I don’t think that you will be able to have access to vision client scripting functions from a script that is a gateway event, but if you put the script into a project library, you could detect which functions are available to you like this:

if hasattr(system, 'perspective'):
     system.perspective.openPopup(...)
elif hasattr(system, 'gui'):
     system.gui.errorBox(...)

Then inside of the if blocks you could call the popup or errorbox functions since you know that one or the other exists at that point. Would that work?
On second thought, I think this will give you the same information as what I suggested already…

I think hasattr(system,‘perspective’) is the key.

In vision the perspective module isn’t loaded unless you are explicit. So I think with a combination of the ApplicationScope and this check I can come up with something.

Thanks!

1 Like

Might be helpful

2 Likes

Thanks!