I feel like there is a simple solution for this that I’m missing. Is there a way to detect from within a script if it is currently being executed in the Client vs in a Gateway script? I have a project script module for caching data that I would like to be able to use for both the Client and Gateway but I need to do some redirecting for helper functions depending on the environment the script is running in. (I should add, I am hoping to avoid having to add an extra input variable that I need to manually set wherever I use this script. Would like some way to automatically detect this from within the script if possible.)
As far as I understand, in perspective all scripts are run on the gateway. In vision I think that you can use these functions to check:
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'
If you don’t want to rely on an internal Ignition package, you can use system.util.getSystemFlags().
@pturmel I knew there had to be something in system.util, but I glazed right over getSystemFlags(). Exactly what I needed. Thanks!
@chandler.teigen Your solution worked great too. Thanks!
Actually I may have spoke too soon. It looks like
system.util.getSystemFlags() cannot be called from the Gateway scope?
AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'getSystemFlags'
I would wrap it in a try/except block.