I am attempting to create a script that will go through a templates custom properties and bind tags to them individually. This would only be used while commissioning the program, meaning the script would only need to run once per template I intend to set up.
I am wondering if it is possible to bind a tag to a component through a script.
Below is the code I have written thus far:
for i in range(15):
tagNum = i
tagStr = str(tagNum)
tagName = "Local:3:I/Pt" + tagStr + "/Data"
event.source.parent.getComponent('PLC1_3_IOCardDisplay16Point').TagB(i)
Then this would be where I bind the tag to the component.
Of course I could do this manually but I believe this will save me time in the future as well as being a learning exercise.
Thank you for any help you can offer.
This looks suspiciously like something that you would be able to do via an indirect binding on a single common template repeated using a template repeater, but I don't know enough about your templates to be able to say for sure.
This seems to possibly be an XY problem. The name of the target tag lines up with 5069 series analog module data, are you just trying to bind the incoming signal data to a template property to display it? Are you able to provide more information on your templates and their expected function?
If I'm correct in my assumption, consider the following approach:
Create a single template called something along the lines of AnalogCardPoint or similar. Create a parameter called baseTagPath and index. Create a custom property called tagValue. Create an indirect tag binding on tagValue that looks something like {1}/{2}/Data. In the box below the indirection string {1} should be linked to baseTagPath and {2} should be linked to Index
You can then take this template and use it in a template repeater. Create 2 custom properties on the template repeater called baseTagPath and pointCount. Create a property change script that has a first line that checks if event.source.propertyName == "baseTagPath" or event.source.propertyName == "pointCount". If it does match, build a template paramters dataset with a row count that matches the value of pointCount, and place this dataset into the templateParameters property of the template repeater.
Technically you could make this template repeater into a template as well, and have baseTagPath as a template parameter.
From there, just place enough copies of the template repeater as there are I/O modules and adjust the baseTagPath and pointCount properties for each to match the respective card.
Thank you for your help. The template repeater paired with indirect bindings is almost exactly what I am looking for. I say almost because I am struggling to get it to work.
I have followed the steps you posted but I seem to be hitting a snag somewhere so I will walk though my understanding of the process.
I have created a single template called AnalogCardPoint. I created two template paramaters (baseTagPath and index) as well as the internal property (tagValue) through the custom properties window in the template. The tagValue internal property is then indirectly bound {1}{2}/Data. This is a nested template so I bound the template parameter boolean, that is tied to the indicator light, to the tagValue. At this point my tag quality is 600 indicating there is an issue with the path.
My understanding of the template repeater is it populates each template within it through the dataset parameters. I am confused as to where the pointCount parameter on the repeater comes into play regarding the template.
For reference the objective of this template is to display the status of the I/O on the card. Previously I was tagging each template separately. If you have any feedback as to why the tag path seems to be broken please let me know.
EDIT: there was likely a typo somewhere in my work as I started from scratch and have been able to get it working. Thank you for your help!
Glad to hear you managed to get it to work. pointCount is there so you can specify how many channels are on the card. Some have 16 (digital I/O), some have 8, some have 4.The intent was that you used a for loop to build the rows of the dataset, using for x in xrange(pointCount) or something similar.