# Vision: Best way to get the Window's rootContainer object from a component

**URL:** <https://forum.inductiveautomation.com/t/vision-best-way-to-get-the-windows-rootcontainer-object-from-a-component/26309>\
**Category:** Ignition\
**Created:** [July 5, 2019, 8:10am UTC](https://forum.inductiveautomation.com/t/vision-best-way-to-get-the-windows-rootcontainer-object-from-a-component/26309 "2019-07-05T08:10:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 5, 2019, 8:10am UTC](https://forum.inductiveautomation.com/t/vision-best-way-to-get-the-windows-rootcontainer-object-from-a-component/26309/1 "2019-07-05T08:10:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 5, 2019, 3:08pm UTC](https://forum.inductiveautomation.com/t/vision-best-way-to-get-the-windows-rootcontainer-object-from-a-component/26309/2 "2019-07-05T15:08:52Z")

</div>

```python
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.

---

<div class="post-metadata">

**Author:** ![chasondeshotel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chasondeshotel/32/20032_2.png) [@chasondeshotel](https://forum.inductiveautomation.com/u/chasondeshotel)\
**Post date:** [July 5, 2019, 5:05pm UTC](https://forum.inductiveautomation.com/t/vision-best-way-to-get-the-windows-rootcontainer-object-from-a-component/26309/3 "2019-07-05T17:05:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 5, 2019, 5:19pm UTC](https://forum.inductiveautomation.com/t/vision-best-way-to-get-the-windows-rootcontainer-object-from-a-component/26309/4 "2019-07-05T17:19:53Z")

</div>

Replace `TopLevelContainer` (and the import) with `com.inductiveautomation.factorypmi.application.FPMIWindow`.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 5, 2019, 8:23pm UTC](https://forum.inductiveautomation.com/t/vision-best-way-to-get-the-windows-rootcontainer-object-from-a-component/26309/5 "2019-07-05T20:23:52Z")

</div>

Thanks Paul! Always so helpful, much appreciated.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 5, 2019, 9:03pm UTC](https://forum.inductiveautomation.com/t/vision-best-way-to-get-the-windows-rootcontainer-object-from-a-component/26309/6 "2019-07-05T21:03:22Z")

</div>

You can also use:  
`system.gui.getParentWindow(event).rootContainer`  
to get the Window’s root container from within a template from an event action.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 6, 2019, 6:59am UTC](https://forum.inductiveautomation.com/t/vision-best-way-to-get-the-windows-rootcontainer-object-from-a-component/26309/7 "2019-07-06T06:59:40Z")

</div>

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:

```auto
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:

```auto
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…

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 6, 2019, 1:45pm UTC](https://forum.inductiveautomation.com/t/vision-best-way-to-get-the-windows-rootcontainer-object-from-a-component/26309/8 "2019-07-06T13:45:57Z")

</div>

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:

> [@Transaction groups triggered expression item updating when trigger is false](http://forum.inductiveautomation.com/t/transaction-groups-triggered-expression-item-updating-when-trigger-is-false/17196/14):
>
> Ok, so I’ve been down the rabbit hole and found Ignition’s (undocumented) PyComponentWrapper. I haven’t deciphered it enough to be sure, but it seems to be invoked only for particular situations, based on the string constants in the class file (like “getComponent” and “getComponents”). To play with this, I constructed a conversion adapter like so: public class PyComponentAdapter implements PyObjectAdapter { public PyComponentAdapter() {} @Override public boolean canAdapt(Object jObj) { …

TL/DR: Install a current version of my [Simulation Aids](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids) module.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 9, 2019, 11:44am UTC](https://forum.inductiveautomation.com/t/vision-best-way-to-get-the-windows-rootcontainer-object-from-a-component/26309/9 "2019-07-09T11:44:29Z")

</div>

Thanks Phil, I’ve downloaded your Simulation Aids and installed it, and now it’s working 🙂 Cheers!
