Template output parameters

Thought I’d share a technique I’ve started using, enabled by objectScript() in v7.7, and possible with runScript() in v7.8. Specifically, how to create an “output” parameter in a template that instances can bind to? Publicly visible template parameters cannot be the destination of a binding inside the template. The solution so far is to create a template parameter and an internal property for each output, bind the appropriate tags/expressions to the internal property, and use the template’s ‘propertyChange()’ event to copy from the internal property to the template parameter.

With the help of objectScript() or the new runScript(), a more direct solution is possible: wrap the binding to the internal property in a function call that will also write to the template parameter. I use the following function in shared.util to handle gui thread property assignments:def assignLater(comp, prop, val, ms = 0): import system def assignLaterInvoked(c=comp, p=prop, v=val): try: setattr(c, p, v) except: c.setPropertyValue(p, v) system.util.invokeLater(assignLaterInvoked, ms) return valNote the return val at the end – it allows this function to work in a binding while also sending the value elsewhere. An example: given template parameters ‘tagfolder’ & ‘output’, this expression binding on an internal property will keep ‘output’ up to date:objectScript("shared.util.assignLater(binding.target, 'output', args[0])", tag("[default]"+{myTemplate.tagfolder}+'/tagname'))I haven’t tested the new runScript() features in Ignition v7.8 yet, but it would be something like this:runScript("shared.util.assignLater(self, 'output', args[0])", 0, tag("[default]"+{myTemplate.tagfolder}+'/tagname'))Two big advantages here: (1) the assignment code stays with the binding & (2) it runs all the time like any other binding.

The utility function could be simplified if you never need the delay – bindings always run on the gui thread (so far). Anyways, hope this helps someone.

3 Likes

Old post, but is this still the method for 8.1.38?

This is Vision.

I have a template that is a bunch of data entry values (OPC tags) that change depending on a popup windows passed parameter. I drop this template into the popup window. From this same popup window I call another popup that needs to know whether all these values are zero or not (that's easy to determine...add them all > 0).

Since the original properties of the values entered in the template aren't exposed to the first popup window, I started looking at creating an output parameter from the template which brought me to this answer.

My choices it seems are the above technique or, creating a custom property on the popup window and just bind an expression of all the OPC tags from the template added together. But since I try to keep multiple tags out of expressions, I've come here to determine the most efficient method.

Yes, still correct. Template parameters are functionally in/out. Vision Templates do not have dedicated output parameters.

(But nowadays, I never use the tag() function.)

Yes, also trying to avoid tag() in any expressions.