Dynamically reading templates on a window

Hello dear Ignited,

I can’t wrap my head around yet simple concept. I have 30+ templates within a “bigger” template (that “bigger” template is then placed on a Main window). Inside this “bigger” template, there is also a button next to these 30+ other templates (these 30+ templates are of the same “class”).

My goal: to select all the templates from the “bigger” template and access their properties. Then, later, use it in a SQL query.

The relevant code for my attempt was as follows and this code is in a button on a template where these 30+ templates reside:

components = event.source.parent.getComponents()

for component in components:
	if 'Z' == component.name[0]: 
		var = str(component.name)
		print component.name, event.source.parent.getComponent(var).is_visible

And that gives me an error of “is_visible not being property of an object”. is_visible is a custom property of the inner template (These 30+ templates in a bigger one). However, if I use e.g. ‘Z12_note’ string inside the getComponent() instead of var, I get what I desire (i.e. value of is_visible for template in current iteration).

What am I missing here? Both var and ‘Z12_note’ are of the same type - str.

Thank you very much for your advices and opinions.

Take care.

Try using:

print component.name, component.getComponent(0).is_visible

Template instances are layered objects–the root container of an instance is not at the same level as the component in the outer container.

Also explore with something like this:

print component.name, type(component.getComponent(0))

Greetings Mr. PTurmel,

Thanks for the feedback, what worked for me was


type(component.getComponent(0)) has returned ‘com.inductiveautomation.factorypmi.application.components.template.VisionTemplate’
Nevertheless, your suggestions have brought me “over the finish line”

Thank you very much for the support.

1 Like