Browse windows, templates with script?

Hi,

I it possible to browse and change windows as with the following pseudo code?

for window in allWindows:
    for component in window.components:
        component.setProperty('propertyName', propertyValue)

and maybe something similar for templates?

Thanks

Sort of. Windows are stored in a binary serialized form, so they have to be open to manipulate them. A script can open a window, manipulate it, and close it again. If in the designer, and the project is then saved, the property change will be present for later Vision clients.

I don't think there's anything like that for templates.

In a Vision client, you can do similar, but changes will not persist until the next open.

1 Like

Find & Replace is the supported way to do this:
https://docs.inductiveautomation.com/display/DOC81/Find+and+Replace

2 Likes

Paul's suggestion is the simplest solution for most scenarios. As the documentation shows, simply select the "All Windows" option and perform the search:
image

However, if it's something complicated that requires scripting, the following code will do the work for you:

for name in system.gui.getWindowNames():
	system.nav.openWindow(name)
	components = system.gui.getWindow(name).getRootContainer().getComponents()
	for component in components:
		#identify your component, and do the necessary work here
	system.nav.closeWindow(name)

Here is a more advanced example that effectively illustrates such a scenario:

2 Likes

The actual task at hand is this:

We have a few base templates which represents pumps, valves, etc.

These templates have been instantiated maybe over 1000 times each and are spread over a large number of windows and other templates.

We now have to assign the base templates a new custom parameter and afterwards it needs to be assigned data on each instance.
The data on each template instance varies so I don't see how i can use search and replace.

What is the best way to go about this?

@justinedwards.jle thanks, that looks promising for our windows :slight_smile:

I'm having a hard time visualizing this. Why can't the custom parameter be the same on each template? What is the data dependent on that makes it different? Is it a window property that you can bind to? Can you put a script in the template that sets the parameter automatically based off of the window it's in?

I love using templates because they automatically inherit changes. They make updates and maintenance quick and easy, but they have to be designed in a way that is universal for there purpose. If an individual modification is required for some scenarios, it's probably better from a maintenance standpoint to simply have more than one template.

1 Like