No Parent Attribute Available

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

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()

try

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

1 Like

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.

What is it you’re trying to achieve ?

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.

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.

There is a built-in function to get the parent window, if it helps:
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

1 Like

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!

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

1 Like

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

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.

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

1 Like

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?

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

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

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

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?

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

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.

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.

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 )