Change colour of background in template at Vision

I want to change the background color of the button when creating a template in VSION. Since I want to change the color according to the value of the corresponding tag using the template property, I tried to write a script as follows in the background expression, but I get an error saying "Nested paths not allowed". What should I do?This template property is integer and I don't want to change this.

if ({[tag path]A/B/C/D/E{template property}.value} < 1, '255,255,255',
    if ({[tag path]A/B/C/D/E{template property}.value} < 2, '255,0,0',
        if (2<{[tag path]A/B/C/D/E{template property}.value}, '0,0,0',
            '0,0,0'
        )
    )
)

Bind the value of this tag to a custom property, and use that property instead of the tag in your expression.

1 Like

To expand a bit on what @pascal.fragnound is saying, the issue here is that Ignition expects the contents of a set of {} to indicate either a tag path or a property path, when it detects the {} inside of that, you get the error you are seeing.

In stead, create a custom property for the value of the tag (note you don't need the .value here and use an indirect binding to use the property as part of the path.

https://docs.inductiveautomation.com/display/DOC81/Indirect+Tag+Bindings+in+Vision

You might also find the color() expression function useful here. You also don't need third if statement as both results are the same. Your resulting expression would look something like this:

if({template property for tag value} < 1, color(255,255,255),
    if({template prperty for tag value} < 2 color(255,0,0),
        color(0,0,0)
    )
)

Sorry for the late reply. I was able to tag the tags I needed with the Indirect Tag using {}. However, I don't know how to change the color depending on the value of the tag I tagged afterwards. Instead of changing the color depending on the {} property of the Indirect Tag, I want to change the color depending on the value of the tag that contains the {} property.

Sorry for the confusion. I want to change the color depending on the value of the Tag I set in the Indirect Tag.

You use the property that you have set the tag binding on, in the color binding.

Doesn't matter if the tag binding is direct or indirect, the binding on the color will still look at the property.

What have you tried and what didn't work? It's difficult to tell exactly what you're struggling with, share some screen shots of how you have set up the bindings and we will be better able to help you.

1 Like

I tried to set the color with the Indirect Tag's Number to Color Translation, but it didn't work. So I tried to control the color by writing a macro in expression, but I couldn't do it because the Tag's path was invalid. The problem seems to be that the tag's path contains the {1} I



used in the Indirect Tag. I don't know what to do.

Looking at the picture, it doesn't look like your changing the template's background color, but rather, a button component within the template. In this case, it would probably be easier bind your tag value to a custom property, and then use the button's style customizer to change its background color. Here as an example from a similar discussion of how to do this:

Correct. You can only use that syntax in an indirect tag, not in an expression's nested tag path. The recommended way to hand this is to make custom properties for each of the tags needed in the expression, use indirection for those, then use the properties in the expression.

2 Likes

Done. Thank you very much!!! I am also very grateful to those who thought with me and gave me advice.

1 Like