Say I have a reference to a component:
obj = self.source #let self be a PMIEasyChart
What’s an efficient way to get the containing Window’s rootContainer object from this?
I can just do a recursive getParent, but I’m hoping there’s a better way
Say I have a reference to a component:
obj = self.source #let self be a PMIEasyChart
What’s an efficient way to get the containing Window’s rootContainer object from this?
I can just do a recursive getParent, but I’m hoping there’s a better way
from com.inductiveautomation.ignition.client.util.gui import IgnitionSwingUtilities
from com.inductiveautomation.vision.api.client.components.model import TopLevelContainer
IgnitionSwingUtilities.getAncestorOfClass(TopLevelContainer, obj)
That’s exactly the method used internally.
Is there any way to get this to work from a template? It seems to only traverse to the top-level of that template, but not to the root container of the window
Replace TopLevelContainer
(and the import) with com.inductiveautomation.factorypmi.application.FPMIWindow
.
Thanks Paul! Always so helpful, much appreciated.
You can also use:
system.gui.getParentWindow(event).rootContainer
to get the Window’s root container from within a template from an event action.
Hmm, I’m trying to use this to get some custom properties defined on a window root container, but for the life of me I can’t work out what’s going wrong…
I have this:
from com.inductiveautomation.ignition.client.util.gui import IgnitionSwingUtilities
from com.inductiveautomation.vision.api.client.components.model import TopLevelContainer
RC = IgnitionSwingUtilities.getAncestorOfClass(TopLevelContainer, obj).rootContainer
print RC.mY
But I get an error saying that mY is not an attribute of RC.
Yet, I’ve used this to successfully read the value in:
RC2 = event.source.parent
print RC2.mY
This may show my lack of understanding of Python, but I also tried this which resulted in TRUE:
print RC == RC2
So I can’t see what the issue is…
You are encountering Ignition's spotty application of its PyComponentWrapper, which is responsible for making custom properties act like regular properties. For more details, see this thread:
TL/DR: Install a current version of my Simulation Aids module.
Thanks Phil, I’ve downloaded your Simulation Aids and installed it, and now it’s working Cheers!