Get current scope in scripting

Is there a way to easily grab the current scope in scripting?

We have a lot of code that will either execute through normal python, tag event scripts, script console, or perspective scripts. And so we need to identify what scope we are in sometimes to verify how we want to handle a task.

I know that I can try to do things like import the gateway context, or do a perspective print, etc, but is there a more rigid test to see Current scope? (Understanding this will fail in normal python, but we can work around that)

1 Like

Options :slight_smile:

Perfect! I guess I didnt search hard enough before I asked lol

My preferred option is probably this one


try:
    from com.inductiveautomation.ignition.common.model import ApplicationScope
    scope = ApplicationScope.getGlobalScope()


    if (ApplicationScope.isClient(scope)):
	    print("Client Scope")

    if (ApplicationScope.isDesigner(scope)):
	    print("Designer Scope")
	
    if (ApplicationScope.isGateway(scope)):
        try:
            system.perspective.print("Perspective Scope")
        except:
	    print("Gateway Scope")
except:
    print("Python Scope")

We’ve got this in a script called env

from com.inductiveautomation.ignition.common.model import ApplicationScope

scope = ApplicationScope.getGlobalScope()


def isDesigner():
	return ApplicationScope.isDesigner(scope)

def isGateway():
	return ApplicationScope.isGateway(scope)
	
def isPerspective():
	return ApplicationScope.isGateway(scope) and hasattr(system,'perspective')

def isVision():
	return ApplicationScope.isClient(scope)

Then call it with env.isGateway() etc…

2 Likes