Refresh Template Repeater data from a template inside of the repeater

I have a Template Repeater I am using to show some templates. Each template has a button that can be pressed to change the order of the templates in the repeater.

Right now the changes are saved to the database, but the only way I can get the template repeater to reflect the changes is to close/open the template window, or to click a button on the same page as the Template Repeater to manually refresh it.

Here is the script I am using. Pretty simple.

TemplateRepeater = event.source.parent.getComponent('Template Repeater')
system.db.refresh (TemplateRepeater, "templateParams")
  • Is there a way I can run this script from a template inside of the repeater?
  • I’m sort of assuming there is not. Could I put a custom property on the Template Repeater that would refresh it’self if a certain value changed on one of the templates?
  • Any other options?

Thanks for the help.

Place your system.db.refresh in a custom method on the repeater. Then within the template, use event.source.parent.parent.customMethod(). (Might need more 'parent’s in there, depending on the depth of your code.)

Thanks! I put the button directly on the template, and then was able to access it by putting event.source.parent.parent.parent.parent.parent.customMethod() on the actionPerformed of the button.

Any idea why it required so many parents? I would have expected 2 - the first to get to the Template, and the second to get to the Template Repeater - rather than 5.

There’s a scrolling view layer and it’s inner window (allowing for scroll bars), plus one more for the template holder analog just below the template root. I think. You can use shared.inspect.introspect() from inspect.py on each layer for more details. See also the shared.inspect.holder() function usable in client/designer scopes.

1 Like

Is there a way to reference a custom method on the template by using a button that is on the same vision window as the template/template repeater?

For context:
I'm attempting to create a Refresh button on a window that also has a template repeater that targets two tables on this template with separate databases associated with each that I would like to refresh.

You'll have to explore the Swing component hierarchy with .getComponent(int). However, you will likely be unable to call the custom method on the retrieved Swing components unless you have my Integration Toolkit module installed (formerly known as Simulation Aids), due to limitations of Ignition's native PyComponentWrapper callsites. See this topic for skull-cracking details:

I did a quick experiment, and this worked on a test template with a custom method that was being rendered by a template repeater:

# Get the loaded templates from the template repeater
templates = event.source.parent.getComponent('Template Repeater').loadedTemplates

# Iterate through them, and call their custom methods
for template in templates:
	template.testMethod()

I usually don't run into the missing PyComponentWrapper unless I access the component using SwingUtilities. On systems that do not have the Integration Toolkit, the wrapper can be put back on the component in this way:

# Import the class that wraps Vision components
from com.inductiveautomation.factorypmi.application.script import PyComponentWrapper

# Get the component in a way that causes it to lose its wrapper \o/
unwrappedComponent = # However you get your component

# Pass the unwrapped component into the PyComponentWrapper,
# ...and it will return the component properly wrapped
wrappedComponent = PyComponentWrapper(unwrappedComponent)
1 Like