# Detect vision or perspective

**URL:** <https://forum.inductiveautomation.com/t/detect-vision-or-perspective/44636>\
**Category:** Ignition\
**Tags:** perspective, ignition80\
**Created:** [March 18, 2021, 2:50pm UTC](https://forum.inductiveautomation.com/t/detect-vision-or-perspective/44636 "2021-03-18T14:50:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [March 18, 2021, 2:50pm UTC](https://forum.inductiveautomation.com/t/detect-vision-or-perspective/44636/1 "2021-03-18T14:50:00Z")

</div>

Ignition v8.1.

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

---

<div class="post-metadata">

**Author:** ![chandler](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@chandler](https://forum.inductiveautomation.com/u/chandler)\
**Post date:** [March 18, 2021, 2:58pm UTC](https://forum.inductiveautomation.com/t/detect-vision-or-perspective/44636/2 "2021-03-18T14:58:47Z")

</div>

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:

```auto
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'

```

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [March 18, 2021, 3:05pm UTC](https://forum.inductiveautomation.com/t/detect-vision-or-perspective/44636/3 "2021-03-18T15:05:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chandler](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@chandler](https://forum.inductiveautomation.com/u/chandler)\
**Post date:** [March 18, 2021, 3:21pm UTC](https://forum.inductiveautomation.com/t/detect-vision-or-perspective/44636/4 "2021-03-18T15:21:50Z")

</div>

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:

```auto
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…

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [March 18, 2021, 3:25pm UTC](https://forum.inductiveautomation.com/t/detect-vision-or-perspective/44636/5 "2021-03-18T15:25:10Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 18, 2021, 5:24pm UTC](https://forum.inductiveautomation.com/t/detect-vision-or-perspective/44636/6 "2021-03-18T17:24:46Z")

</div>

> [@Way to print for both perspective and vision projects?](http://forum.inductiveautomation.com/t/way-to-print-for-both-perspective-and-vision-projects/34793/2):
>
> from \_\_future\_\_ import print\_function import \_\_builtin\_\_ from java.lang import IllegalArgumentException def print(\*objects, \*\*kwargs): sep = kwargs.pop("sep", ", ") end = kwargs.pop("end", "\n") message = sep.join(str(object) for object in objects) try: system.perspective.print(message) except IllegalArgumentException: system.util.getLogger("utils.print").info(message) except AttributeError: \_\_builtin\_\_.print(message, end=end) Dropped in a utils script module. I would definitely …

Might be helpful

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [March 18, 2021, 5:31pm UTC](https://forum.inductiveautomation.com/t/detect-vision-or-perspective/44636/7 "2021-03-18T17:31:49Z")

</div>

Thanks!
