Monday, February 16, 2015

Ignition Template Repeaters

New to Ignition V7.7 are Template Repeaters and Template Canvas. These two tools can save tons of time, if you use them to their full potential. When you combine Tag Data Types and templates, you can now dynamically build pages with ease.


The Template Repeater allows you to repeat one template as many times as you want. The Repeat Behavior allows two choices: Count and Dataset.







Count is the simplest. Just select Count in the Repeat Behavior, then put the number you want in the Repeat Count. On the template itself, you need to add the template property: 'index' as an integer. This will get the instance number of the template. Then use this index number in an sql query to get a tag path from a database.


Dataset is the the other Repeat Behavior. Each name column in the dataset is the parameter you would like to pass. For my example, I created a template for Analog Instrument Alarms. I need two parameters to make the template work, Alarm and Tagpath. So I created those columns.












For each row of data I add to the dataset, another template is added to the repeater. If the templates outgrown the template repeater size, a scroll bar will be added to the side and/or bottom.











Now you can add each row of data manually; however, I am using Tag Data Types. And this template is for use with my AI_STD data type. I added a custom property to the Template Repeater called 'path'. I then add the parent path that I want to look for my Data Type: 'AI_STD' in. Now I call my script 'template_analog' to build my data table. I bind the Template Parameters to my script and pass the path I want it to look under. Then have it return the dataset. This makes the page dynamically every time the page is loaded. I also look to see if the scaling, high high, high, low, or low low alarms are used and if so add the row to the dataset.

Here is the code for the 'template_analog' script:


def template_analog(path):
import system

# Create the rows for the dataset
rows = []
tags = system.tag.browseTags(parentPath = path, udtParentType = 'AI_STD', sort ="ASC")
row_count = 0

for tag in tags:
readtags = [tag.path + "/USESCALE", tag.path + "/USEHHALM", tag.path + "/USEHALM", tag.path + "/USELALM", tag.path + "/USELLALM"]
scl,hh,h,l,ll = system.tag.readAll(readtags)
row_count += 1

if scl.value:
sclrow = ["ALM", tag.path]
rows.append(sclrow)
if hh.value:
hhrow = ["HHALM", tag.path]
rows.append(hhrow)
if h.value:
hrow = ["HALM", tag.path]
rows.append(hrow)
if l.value:
lrow = ["LALM", tag.path]
rows.append(lrow)
if ll.value:
llrow = ["LLALM", tag.path]
rows.append(llrow)

# Create the dataset to send back.
headers = ["Alarm", "TagPath"]
return system.dataset.toDataSet(headers, rows)




With this simple code, I can create all the analog alarms used instantly. It saves time and also avoids mistakes. Hope this helps with your next project.


No comments:

Post a Comment