Get current scope in scripting

There are a number of topics about this, with this being the only topic that works to distinguish between gateway and perspective :slight_smile: thanks @PGriffith and @hunterdg

I've incorporated this into @Kyle_Chase 's script from this topic:

from com.inductiveautomation.ignition.common.model import ApplicationScope
try:
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	isGateway = True
except ImportError:
	isGateway = False

def getScope():
	scope = ApplicationScope.getGlobalScope()
	
	if ApplicationScope.isClient(scope):
		return "vision"

	elif ApplicationScope.isDesigner(scope):
		return "designer"

	elif ApplicationScope.isGateway(scope):
		pageModel = IgnitionGateway.get().moduleManager.resolveClass("com.inductiveautomation.perspective.gateway.model.PageModel")
		if pageModel.PAGE.get() is not None:
			return "perspective"
		return "gateway"
	
	else:
		raise ValueError("Could not resolve execution scope!")
1 Like