# Adding Tag Bindings to Components Through a Script

**URL:** <https://forum.inductiveautomation.com/t/adding-tag-bindings-to-components-through-a-script/97416>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [October 17, 2024, 6:49pm UTC](https://forum.inductiveautomation.com/t/adding-tag-bindings-to-components-through-a-script/97416 "2024-10-17T18:49:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Day\_N](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@Day\_N](https://forum.inductiveautomation.com/u/Day_N)\
**Post date:** [October 17, 2024, 6:49pm UTC](https://forum.inductiveautomation.com/t/adding-tag-bindings-to-components-through-a-script/97416/1 "2024-10-17T18:49:27Z")

</div>

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:

```python
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.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [October 17, 2024, 7:44pm UTC](https://forum.inductiveautomation.com/t/adding-tag-bindings-to-components-through-a-script/97416/2 "2024-10-17T19:44:08Z")

</div>

> [@Day\_N](#):
>
> custom properties and bind tags to them individually.

> [@Day\_N](#):
>
> `tagName = "Local:3:I/Pt" + tagStr + "/Data" `

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](https://en.wikipedia.org/wiki/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?

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [October 17, 2024, 7:51pm UTC](https://forum.inductiveautomation.com/t/adding-tag-bindings-to-components-through-a-script/97416/3 "2024-10-17T19:51:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Day\_N](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@Day\_N](https://forum.inductiveautomation.com/u/Day_N)\
**Post date:** [October 18, 2024, 3:53pm UTC](https://forum.inductiveautomation.com/t/adding-tag-bindings-to-components-through-a-script/97416/4 "2024-10-18T15:53:29Z")

</div>

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.  
 ![tag issue](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/7/5732ff7a0392869d63faff4e25f4bcede2fe2628.jpeg)

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!

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [October 18, 2024, 6:45pm UTC](https://forum.inductiveautomation.com/t/adding-tag-bindings-to-components-through-a-script/97416/5 "2024-10-18T18:45:51Z")

</div>

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.
