# Dynamic tag bindings in a property expression?

**URL:** <https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498>\
**Category:** Ignition\
**Tags:** scripting, vision\
**Created:** [June 6, 2024, 4:57pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498 "2024-06-06T16:57:38Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Burrick](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@Brandon\_Burrick](https://forum.inductiveautomation.com/u/Brandon_Burrick)\
**Post date:** [June 6, 2024, 4:57pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/1 "2024-06-06T16:57:38Z")

</div>

I have an indicator for a conveyor. it uses 3 different tags from the plc to drive various states. I tried to create an expression that grabs the name of the component to dynamically change the names of these tags so that I can just copy and paste the indicator then change the name. I found that the expression function does not like this.

Code that works looks like this:

```python
if ({[default]ROOT/MAPS/OVLD/S6810_OVLD} = 1, 
	4,
	if ({[default]ROOT/MAPS/FULL/S6810_FULL} = 1,
		3,
	 	if ({[default]ROOT/MAPS/FULL/S6810_AUX} = 1,
	 	1,
	 	0)))

```

I want this:

```python
if ({[default]ROOT/MAPS/OVLD/ + component.name +_OVLD} = 1, 
	4,
	if ({[default]ROOT/MAPS/FULL/ + component.name +_FULL} = 1,
		3,
	 	if ({[default]ROOT/MAPS/FULL/ + component.name +_AUX} = 1,
	 	1,
	 	0)))

```

If this can't work is there a different way to make this happen or will I need to copy paste the script and change the names in the script every time I want a new indicator?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 6, 2024, 5:24pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/3 "2024-06-06T17:24:18Z")

</div>

Try this:

 ![Fancy tag binding](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/e/8e1566c0ae6f30e4e1f0d44fa92581e03ea88c93.png)

The expression binding should be modified to wherever your `componentName` is stored.  
`"[default]ROOT/MAPS/OVLD/" + {view.custom.componentName}`

The expression transform:

```python
if(
	tag({value} + "_OVLD") = 1, 
	4,
	if (
		tag({value} + "_FULL") = 1,
		3,
	 	if (
	 		tag({value} + "_AUX") = 1,
	 		1,
	 		0
	 	)
	)
))

```

And if the tags are bools it can be reduced to,

```python
if( tag({value} + "_OVLD"), 4,
	if (tag({value} + "_FULL"), 3,
		if (tag({value} + "_AUX") , 1, 0))))

```

Generally though, we avoid the tag() function. If you explain your configuration a bit more someone will suggest some improvements.

---

<div class="post-metadata">

**Author:** ![Brandon\_Burrick](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@Brandon\_Burrick](https://forum.inductiveautomation.com/u/Brandon_Burrick)\
**Post date:** [June 6, 2024, 5:28pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/4 "2024-06-06T17:28:55Z")

</div>

I forgot to mention this is in vision and not perspective. Does this affect anything?

I don't have the options check box in vision.

Also added information: This expression is on a custom template property.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 6, 2024, 5:52pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/5 "2024-06-06T17:52:13Z")

</div>

> I forgot to mention this is in vision and not perspective.

That would have been nice to know.

> Does this affect anything?

Yes. Vision doesn't have expression transforms.

Please edit the question title and add the vision tag from the dropdown.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 6, 2024, 6:07pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/6 "2024-06-06T18:07:15Z")

</div>

Caution: While as @Transistor shows, the `tag()` expression will work, it is strongly recommended that you avoid it's use for basically anything outside of expression tags. Enough of this in the UI will kill your performance.

The proper way to accomplish this type of thing is to use indirect tag bindings. Something like:

1. Create a custom property to hold the value of each tag.
2. For each custom property use an indirect tag binding to reference the component name in the tag path.
3. Then you can change your Expression to the following:

```python
case(
    binEnc( {indicator.AUX},{indicator.FULL},{indicator.OVLD}),
    4,4,
    2,3,
    1,1,
    0
)

```

NOTE: Order in the binEnc is important. I would be very tempted to change the result for `FULL` from 3 to 2. Then you could just simply use a `binEnc()` expression so long as other logic insures that only one of the tags are ever true.

If you want to emulate exactly what your `if()` expression does that would look like:

```python
case(
    binEnc( {indicator.AUX},{indicator.FULL},{indicator.OVLD}),
    6,4,
    5,4,
    4,4,
    3,3,
    2,3,
    1,1,
    0
)

```

---

<div class="post-metadata">

**Author:** ![Brandon\_Burrick](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@Brandon\_Burrick](https://forum.inductiveautomation.com/u/Brandon_Burrick)\
**Post date:** [June 6, 2024, 6:12pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/7 "2024-06-06T18:12:13Z")

</div>

Sorry about that. I am new to ignition and this is my first post here.

---

<div class="post-metadata">

**Author:** ![Brandon\_Burrick](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@Brandon\_Burrick](https://forum.inductiveautomation.com/u/Brandon_Burrick)\
**Post date:** [June 6, 2024, 7:30pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/8 "2024-06-06T19:30:09Z")

</div>

Do I need to replace "Indicator" with something that is specific to my project or is "indicator" a universal descriptor?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 6, 2024, 7:32pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/9 "2024-06-06T19:32:54Z")

</div>

> [@Brandon\_Burrick](#):
>
> Do I need to replace "Indicator" with something that is specific to my project

Yes, it will be the path to wherever you actually create the custom properties.

---

<div class="post-metadata">

**Author:** ![Brandon\_Burrick](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@Brandon\_Burrick](https://forum.inductiveautomation.com/u/Brandon_Burrick)\
**Post date:** [June 6, 2024, 7:37pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/10 "2024-06-06T19:37:54Z")

</div>

component.aux?

If I were to use the path using the root container then it would go against the purpose of making the custom properties in an effort to be able to copy, paste then rename the indicator.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 6, 2024, 7:50pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/11 "2024-06-06T19:50:42Z")

</div>

You can make the properties on the comment itself, or better yet create a template and create the properties there. Just make sure that you make the device name property external so you can set it from outside the template.

---

<div class="post-metadata">

**Author:** ![Cory.grube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cory.grube/32/20476_2.png) [@Cory.grube](https://forum.inductiveautomation.com/u/Cory.grube)\
**Post date:** [June 6, 2024, 7:54pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/12 "2024-06-06T19:54:43Z")

</div>

Adding on, this is called template indirection in the docs. For reference: [Template Indirection | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/ignition-modules/vision/vision-templates/template-indirection)

---

<div class="post-metadata">

**Author:** ![Brandon\_Burrick](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@Brandon\_Burrick](https://forum.inductiveautomation.com/u/Brandon_Burrick)\
**Post date:** [June 6, 2024, 8:01pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/13 "2024-06-06T20:01:38Z")

</div>

Yeah, I am using a template.

Thank you guys, I should be able to figure it out. The information has been incredibly useful.

---

<div class="post-metadata">

**Author:** ![Brandon\_Burrick](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@Brandon\_Burrick](https://forum.inductiveautomation.com/u/Brandon_Burrick)\
**Post date:** [June 6, 2024, 8:36pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/14 "2024-06-06T20:36:51Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/9/f9e6540f7e001880aeb8efcf91a302f2f25c80b2.png)

Inside the Indirect tag binding, It does not like component.name.

If I use:

"[default]AEO\_MS/MAPS/AUX/"component.name"+"\_AUX""

or

"[default]AEO\_MS/MAPS/AUX/"+"Component.name"+"\_AUX""

It will take it, but it doesn't seem to link to the tags.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [June 6, 2024, 9:09pm UTC](https://forum.inductiveautomation.com/t/dynamic-tag-bindings-in-a-property-expression/91498/15 "2024-06-06T21:09:30Z")

</div>

Is your template named "component"? If not, that won't work. When you pick a property for the indirection, make sure you're using the picker instead of freely typing in something

Edit: Also, remove your quotes on the indirect tag.
