I was working on a template where I had to display steps in a sequence on the HMI. The number of steps could change from sequence to sequence and the template required a few parameters.
I decided to go with the template repeater component, but that component only provides you with two options regarding how the template is configured.
There are also occasions where templates that would appear in the middle of the layout should not be visible for one reason or another. I would want to shift the items below the invisible item up so that any blank space would be eliminated.
To solve this problem, I needed to create the dataset dynamically with a python script, then bind the resulting dataset to the Template Parameter property of the template repeater. This is a step by step tutorial on how I solved this problem.
3. We are going to add a custom method to the template repeater component you placed on your display. Ensure the component is selected and click the “Scripting…” item in the toolbar.
Figure 3 - Open Script Window
4. When the Component Scripting window opens; do the following:
1) Double click the “Add Method” item on the right. This will create a new blank method where you can write your code.
2) Enter a name for the method. I called mine “buildDataset”
3) List the parameters required by your custom method separated by commas. In this example only one parameter is needed; “path”. The custom method automatically passes the component that contains the script and can be referenced using the keyword “self”. If your template requires more than one parameter, you would list them as “arg1, arg2, arg3” and so on.
4) Write your script. I wanted to create a variable number of items in the repeater depending on how many steps there were in the sequence. Fortunately, the sequencer I am using has a tag that indicates how many steps exist. I bound that tag to the template repeaters Repeat Count property, so I could use it in my script. Here is a run-down on how this script works:
-This script will need to return a DataSet typed variable and will require the system library, so we need to import “system”
import system
-Create an array to hold the data rows
rows = []
-Create the headers for the dataset. For my template, we need an “Index” and “path” parameters.
headers = [“Index”, “path”]
-Execute a for loop to iterate through the number steps in the sequencer. I accomplish this by using the Repeat Count property of the template repeater which I bound to a tag with the maximum step index. The Repeat Count parameter is referenced using the “self” keyword. The Ignition user manual lists all the parameters that can be used in these kinds of scripts.
for x in range (self.repeatCount):
-step 0 is not used in my sequencer, it is reserved as an empty step and I do not want to include it in my dataset. If there are any other conditions that you would not want to include the row in the dataset, this is where you would include them.
if x>0:
rows.append([x, path])
-Return the data as a dataset, so that it can bind to the “Template Parameters” property.
return system.dataset.toDataSet(headers, rows)
-Here is the whole script:
5) Click the ok button to close the Scripting window.
5. Click the binding button for the “Template Parameters” property of the template repeater. This will open the Property Binding window. You will want to bind using the “Expression” option.
6. Bind the custom method to the “Template Parameters” property using the runScript function. The syntax is: runScript(self.nameOfScript, polling rate, parameters)
7. The template repeater will now self-populate based on the tag indicated by the “path” parameter and the Repeat Count property. The Repeat Count property can be bound to a PLC tag or entered on the fly. This technique can be expanded to add field validation to parameters, or any number of advanced functionality.
Jamie has left Hallam-ICS to pursue other endeavors. If you have questions about this article or other Ignition questions, contact Burton Preston. Burton is a Gold Certified Ignition developer.
Hallam-ICS is an engineering and automation company that designs MEP systems for facilities and plants, engineers control and automation solutions, and ensures safety and regulatory compliance through arc flash studies, commissioning, and validation. Our offices are located in Massachusetts, Connecticut, New York, Vermont and North Carolina and our projects take us world-wide.