Templates within Templates

Hi,

I can’t seem to access a template within a template when scripting.

Say for example I have a template called ‘parent’, and inside that template there is another template called ‘child’. The template ‘child’ has a property called ‘value’. How can I edit this ‘value’ from scripting?

I’ve tried things like:

event.source.getComponent('parent').getComponent('child').value

Or

event.source.getComponent('parent').child.value

But I’m really just guessing… Anybody know the correct syntax?

Cheers,
Keiran

So close! Assuming the event is on a sibling component of the parent template:event.source.parent.getComponent('child').valueBut note, value has to be a template parameter, not an internal parameter.

Thanks Phil,

I think my choice of the name ‘parent’ was a very poor one! Let’s say the parent template is now called ‘mother’, and inside that template is another template called ‘child’. If I have a value display on my root container that I want to display the value of a child, and I have no binding between templates (i.e. child.value is not bound to mother.value), how can I access that child.value?

event.source.parent.getComponent('child').value

This would give me an error because there is no component called ‘child’ at this level, only ‘mother’. I want to get the ‘mother’ component and then “burrow in” to the ‘child’ template. Doable?

Cheers,
Keiran

I guess you’re struggling with how property names and component names work.
The syntax ‘.parent’ doesn’t reference a component named ‘parent’, it references the container of the object it is applied to. It’s a built-in property that corresponds to java Components’ getParent() method. In an event routine, ‘event.source’ is the component that fired the event. ‘event.source.parent’ is the container of that component. Containers are components that hold other components and therefore have additional methods to iterate, search or otherwise reference their children. One of those is the .getComponent(someString) that will search through the children looking for the first one that has that name. In your example with a child named ‘child’, you must use .getComponent(“child”) from its container. .child won’t work.
So Ignition’s components sit within containers, which are themselves components within other containers. The root Container is held within a window, not a container. Windows do have .getParent() methods, though, and the hierarchy goes all the way “up” to the application window itself. Windows also have .getRootContainer() methods, which can be abbreviated as .rootContainer for your convenience. If you’d like an example of traversing through all object parents, look at my script in this topic.
Templates add a bit of extra complexity, as there are undocumented component layers between one of the template holders and the template instance itself. Traversing all parents from a script on a button inside a template will give you a look at all of them.

Side note: the abbreviation system is largely built-in to jython, following NetBeans getter/setter naming conventions. Ignition extends this system to include custom properties in most places.

Thanks Phil,

Not struggling with components and names (too much!), that’s why I was verifying I didn’t mean parent the component and so changed the name hoping the question would make more sense. What I was after was the simple “set/getPropertyValue” function. That sorted me out.

Cheers,
Keiran