From a script, can I tell what scope it's running from? e.g. Gateway, Perspective, Vision, Designer, etc.
I want to display an error popup, but the call is different for different scopes
From a script, can I tell what scope it's running from? e.g. Gateway, Perspective, Vision, Designer, etc.
I want to display an error popup, but the call is different for different scopes
This is 2019 so whilst perspective was out then (April 2019 = 8.0.0) it doesn't mention that scope and may need tweaked for it
That's very useful! Hmm. I'll have to see if I can get it to return if it's in Perspective
Testing in perspective returns a gateway scope.
from com.inductiveautomation.ignition.common.model import ApplicationScope
scope = ApplicationScope.getGlobalScope()
if scope == ApplicationScope.GATEWAY:
...
if scope == ApplicationScope.CLIENT:
...
if scope == ApplicationScope.DESIGNER:
...
if scope == ApplicationScope.ALL:
...
if scope == ApplicationScope.NONE:
...
What events/context would trigger .ALL or .NONE?
None. You'll only ever get one of the three C/D/G values as the current scope for a script. The other values are used in other areas, but will never be returned as the current scope.
I recommend using hasattr()
to probe the available functions in system.*
to determine what is possible, preferably done at the top level of a script module with results placed into top-level booleans.
This is what we do to determine scope in a script
from com.inductiveautomation.ignition.common.model import ApplicationScope
def getScope():
scope = ApplicationScope.getGlobalScope()
if ApplicationScope.isClient(scope):
return "c"
if ApplicationScope.isDesigner(scope):
return "d"
if ApplicationScope.isGateway(scope):
if "perspective" in dir(system):
return "p"
return "g"
return "u"