# No Parent Attribute Available

**URL:** <https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914>\
**Category:** Ignition\
**Created:** [March 7, 2022, 3:43pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914 "2022-03-07T15:43:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [March 7, 2022, 3:43pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/1 "2022-03-07T15:43:35Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/3/b334bc34222ff437c4433caec3df94adb572de85.png)

Hey guys!!

I was wondering if anyone can break down on what this error means and how I can fix it? I would appreciate any help that may come.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/5/a56870f531059dcd354106b80493c1eaa4075bcd.png)

In the script (shown above) it looks like this that Line 39 is referring to. Another thing to know is that this is under the “Action Performed” for a button component.

ORIGINAL CODE:

```
from java.awt import Font
from com.inductiveautomation.factorypmi.application import VisionDesktop
from com.inductiveautomation.factorypmi.application.components.template import VisionTemplate
desktop_handle = VisionDesktop.CURRENT_DESKTOP.get()

system.gui.openDesktop(windows = ['Popups/MultitrendWindow'], title = "Multi Trend", handle = "Multi Trend", width = 830, height = 705, x = 350, y = 100)
window = system.gui.desktop("Multi Trend").getWindow('Popups/MultitrendWindow')

windows = system.gui.desktop(desktop_handle).getOpenedWindowNames()
found = False

try:
    system.gui.openDesktop(windows = ['Popups/MultitrendWindow'], title = "Multi Trend", handle = "Multi Trend", width = 830, height = 705, x = 350, y = 100)
except:
    pass
	
for path in windows:
    if 'Popups/MultitrendWindow' in path:
	    found = True
	    break
	
if not found :
    system.nav.desktop("Multi Trend").swapTo('Popups/MultitrendWindow', {'new_tags':system.dataset.toDataSet(['tag'], [[event.source.parent.tagPath]]), 'trend_tags':
system.dataset.toDataSet([], [[]])})

window2 = system.gui.desktop("Multi Trend").getWindow('Popups/MultitrendWindow'
if not found:
    parent = event.parent #original: self.parent
    while type(parent.parent) != VisionTemplate:
	    parent = parent.parent #Original: parent.parent
    new_x = parent.getX() + 100
	
	try:
			# system.nav.getCurrentWindow() will throw an exception when called in the Designer
		root = system.gui.getWindow(system.nav.getCurrentWindow()).getRootContainer()
		if parent.getX() > round(root.getWidth()/2):
			new_x = parent.getX() - 100 - window.getWidth()
	except:
		pass
	new_y = parent.getY()

	try:
			# system.nav.getCurrentWindow() will throw an exception when called in the Designer
		if new_y + window.getHeight() > root.getHeight():
			new_y = root.getHeight() - window.getHeight()
	except:
		pass

window2.getRootContainer().new_tags = system.dataset.toDataSet(['tag'], 
[[event.source.parent.tagPath]])
window2.getRootContainer().configChart()
```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 7, 2022, 3:48pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/2 "2022-03-07T15:48:19Z")

</div>

try

```python
while type(parent.parent) is not None:
    parent = parent.parent

```

and see where it stops

Also, don’t screenshot your code, copy paste it and surround it with triple backticks like this  
```python  
code  
```

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [March 7, 2022, 4:23pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/3 "2022-03-07T16:23:24Z")

</div>

Currently, the view I am trying to edit is being edited by someone else, so I can not test it out at the moment. I will get to as soon as I can access it and provide some feedback. Thank you so much!

If the error persists, is it possible if I can bypass it?

It seems the overall function that I want it to do works, but this error is something I do not want to appear during one of my client’s use.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 7, 2022, 4:24pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/4 "2022-03-07T16:24:10Z")

</div>

What is it you’re trying to achieve ?

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [March 7, 2022, 4:26pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/5 "2022-03-07T16:26:38Z")

</div>

Opening a popup window within a new desktop window to allow the user to drag the popup onto another desktop screen and perform its usual functions within that popup window. This is what I have been working on and this function works fine, it is just that the error that I mention shows whenever I the action is performed for the button component.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 7, 2022, 4:35pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/6 "2022-03-07T16:35:56Z")

</div>

I don’t know vision at all, but here’s the most obvious reason that I can think of for your script to fail:  
The comparison `type(parent.parent) != VisionTemplate` is never true, and thus it ends up reaching the top level, gets `None` as its parent, then fails.

Make sure `VisionTemplate` is the proper thing to check for. Also, you could try with `isinstance(parent.parent, VisionTemplate)` instead of `type()`.

If you’re trying to reach the top-most level as I think you are, and there’s no built-in function or method to get it, maybe you could start from `root`, as it seems you’re already using functions to get it. I expect `root.parent` will be the top-most thing in the hierarchy.

---

<div class="post-metadata">

**Author:** ![rbabcock](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rbabcock/32/13425_2.png) [@rbabcock](https://forum.inductiveautomation.com/u/rbabcock)\
**Post date:** [March 8, 2022, 3:27pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/7 "2022-03-08T15:27:42Z")

</div>

There is a built-in function to get the parent window, if it helps:  
[https://docs.inductiveautomation.com/display/DOC81/system.gui.getParentWindow](https://docs.inductiveautomation.com/display/DOC81/system.gui.getParentWindow)

Edit: Though looking at it now, I’m not sure that it’s available in version 7…  
Edit 2: it is:  
[https://docs.inductiveautomation.com/display/DOC79/system.gui.getParentWindow](https://docs.inductiveautomation.com/display/DOC79/system.gui.getParentWindow)

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [March 8, 2022, 5:31pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/8 "2022-03-08T17:31:34Z")

</div>

Hey again!

I just wanted to give an update and I implemented your suggestions from yesterday but still no luck. I will continue to go in that same route and see if I can find something else. I do want to thank you for all the help, I greatly appreciate for pushing me in the right direction!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 8, 2022, 5:41pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/9 "2022-03-08T17:41:21Z")

</div>

try `parent = event.parent`. self doesn’t exist in vision.

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [March 8, 2022, 5:46pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/10 "2022-03-08T17:46:18Z")

</div>

So I gave it a shot and a different error came up:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/5/4505029355a92b3ef2d3504ee75ec839c62ae73b.png)

Just to give some key points. I have a second desktop view that I use for a popup to appear on it. The reason being is that my client wanted that popup to be able to drag across monitors. It still functions as it should, its just that I am unsure how to overcome this error.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 8, 2022, 5:47pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/11 "2022-03-08T17:47:11Z")

</div>

Oops. try `event.source`, instead. That should get you to the button level, then parent from there.

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [March 8, 2022, 5:56pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/12 "2022-03-08T17:56:04Z")

</div>

Okay, I edited it and it gives me the same error as before. About ‘NoneType’ object not having the parent attribute. Is self essentially event.source?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 8, 2022, 6:03pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/13 "2022-03-08T18:03:20Z")

</div>

Okay took a look at some of my code. This goes all the way to the top. Feel to modify as needed.

```python
parent = event.source
while parent is not None:
    win = parent
    print type(win)
    parent = win.getParent()

```

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [March 8, 2022, 6:11pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/14 "2022-03-08T18:11:41Z")

</div>

> [@JordanCClark](#):
>
> ```python
> parent = event.source
> while parent is not None:
> win = parent
> print type(win)
> parent = win.getParent()
> 
> ```

You mean add this before the from lines in my code? My code is pasted in the original post for reference. I also wanted to say thank you thus far!

Edit 2: Scratch that, I know where. Going to see what it prints and update this post with any updates

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [March 8, 2022, 6:24pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/15 "2022-03-08T18:24:51Z")

</div>

Okay, I tried looking into the Console what the print is, but nothing prints out except for the errors.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 8, 2022, 7:04pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/16 "2022-03-08T19:04:59Z")

</div>

> [@Jose\_Diaz](#):
>
> I tried looking into the Console

The "Script Console" or the "Output Console".

Note: This code will not work in the Script Console, so I suspect you mean the output console. What does your script now look like?

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [March 8, 2022, 7:26pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/17 "2022-03-08T19:26:28Z")

</div>

Yes sorry, I was referring to the Output Console. And my script looks like how it shown in the original post. Was there something I did incorrect on the previous reply to Jordan? I can try again

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 8, 2022, 7:42pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/18 "2022-03-08T19:42:24Z")

</div>

I don’t know, because I don’t know where you inserted the code provided by Jordan.

Assuming that `event.source` is truly not `None` then it should have printed something.

---

<div class="post-metadata">

**Author:** ![Jose\_Diaz](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@Jose\_Diaz](https://forum.inductiveautomation.com/u/Jose_Diaz)\
**Post date:** [March 8, 2022, 7:53pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/19 "2022-03-08T19:53:53Z")

</div>

```
from java.awt import Font
from com.inductiveautomation.factorypmi.application import VisionDesktop
from com.inductiveautomation.factorypmi.application.components.template import VisionTemplate
desktop_handle = VisionDesktop.CURRENT_DESKTOP.get()

system.gui.openDesktop(windows = ['Popups/MultitrendWindow'], title = "Multi Trend", handle = "Multi Trend", width = 830, height = 705, x = 350, y = 100)
window = system.gui.desktop("Multi Trend").getWindow('Popups/MultitrendWindow')

windows = system.gui.desktop(desktop_handle).getOpenedWindowNames()
found = False

try:
    system.gui.openDesktop(windows = ['Popups/MultitrendWindow'], title = "Multi Trend", handle = "Multi Trend", width = 830, height = 705, x = 350, y = 100)
except:
    pass
	
for path in windows:
    if 'Popups/MultitrendWindow' in path:
	    found = True
	    break
	
if not found :
    system.nav.desktop("Multi Trend").swapTo('Popups/MultitrendWindow', {'new_tags':system.dataset.toDataSet(['tag'], [[event.source.parent.tagPath]]), 'trend_tags':
system.dataset.toDataSet([], [[]])})

window2 = system.gui.desktop("Multi Trend").getWindow('Popups/MultitrendWindow')
if not found:
    parent = event.source
    while parent is not None:
        win = parent
        print type(win)
        parent = win.getParent()
    new_x = parent.getX() + 100
	
	try:
			# system.nav.getCurrentWindow() will throw an exception when called in the Designer
		root = system.gui.getWindow(system.nav.getCurrentWindow()).getRootContainer()
		if parent.getX() > round(root.getWidth()/2):
			new_x = parent.getX() - 100 - window.getWidth()
	except:
		pass
	new_y = parent.getY()

	try:
			# system.nav.getCurrentWindow() will throw an exception when called in the Designer
		if new_y + window.getHeight() > root.getHeight():
			new_y = root.getHeight() - window.getHeight()
	except:
		pass

window2.getRootContainer().new_tags = system.dataset.toDataSet(['tag'], 
[[event.source.parent.tagPath]])
window2.getRootContainer().configChart()

```

My Apologies, here is where I put it.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 8, 2022, 8:00pm UTC](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914/20 "2022-03-08T20:00:53Z")

</div>

Does your path include ‘Popups/MultitrendWindow’?

if `found` is `True` then this code wouldn’t be executed.

Also, possibly just a copy paste error, but this:  
`window2 = system.gui.desktop("Multi Trend").getWindow('Popups/MultitrendWindow'`

is invalid as it’s missing a closing `)`

[Next page](https://forum.inductiveautomation.com/t/no-parent-attribute-available/56914.md?page=2)
