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)
from com.inductiveautomation.ignition.gateway import IgnitionGateway
pageModel = IgnitionGateway.get().moduleManager.resolveClass("com.inductiveautomation.perspective.gateway.model.PageModel")
if pageModel.PAGE.get() is not None:
# in a page
Subject to change between Ignition versions and Perspective module versions; class names should be considered an implementation detail.
What's the ultimate use case for this kind of introspection?
anyone have success getting custom code/module/component/binding/etc scripting/context tracebacks as well as Ignition does with native logger/console exceptions?
end goal is to never have to specify a logger "name" in system.util.getLogger() - i just want it to know exactly where it is - all the way down to the component/script/function name - from wherever I call it
Basically, no, there's no great way to do so at the moment.
I filed a ticket a few months ago to make sure that we're adding context where we have it, probably via the __file__ or __name__ or something standard variables.
Will this help distinguish between a proper Perspective session (ie: button on a Perspective View calling a function) and a function being called from a Perspective session but via an asynchronous thread. ?