Creating Pipe Color Changes in a Circuit

Hello,

I'm trying to have the pipe color change for flow path based on valve positions, and if pump is running. I can make the custom property for color change based on tag value, but it's only for certain circuits. I was thinking I'd have to use a custom expression, if so, what would be the best expression? What I've tried so far hasn't worked, but i'm still learning the expression side of ignition.

if you have only two states to represent by colors, then just use if, if you have more than two states use case

if({[default]SomeTag},'#00FF00','#FF0000')
case({[default]SomeTag},
	1, '#00FF00',
	2, '#FF0000',
	'#000000'  //default case
)
1 Like

Will this work for the vision color codes? Can I do the && to add multiple valves into the color sequence?

I'm having a hard time fully understanding what you are trying to do. Got any screenshots, or can give more detail on exactly what you are trying to achieve?

When 6600, p600 and valves in line are active I want to change the color of the pipe.

I missed the vision tag on the post, you'll have to use the color expression function to return a color object.

1 Like

If you need mulitple conditions to be true in order for the color to change, then you'll probably want a case statement

case(true,
	{tag1} && {tag2}, color(0,255,0),
	{tag1} && {tag3}, color(255,0,0),
	color(0,0,0)
)

ok, I will try this.

Thank you so much for the help.

1 Like

I've never seen a case statement implemented like that, with a literal in the value and expressions in each case. Pretty clever way to avoid having a bunch of nested ifs for sure.

1 Like

Another option would be the binEnc expression function to express a series of booleans as a derived integer state, where each input bit == one bit of the output integer. You could use that to separate the logic about what state things are in from the UI/presentation, potentially.

4 Likes

I'm sorry, I'm not that experienced to understand what you're stating. Went over my head. :frowning:

So, binEnc takings a series of boolean inputs, e.g.:
binEnc(true, false, true, false)
It then treats those inputs as binary bits, e.g:
1110
Which, parsed least -> most significant, can become an integer:
1 -> the '1's place is true, so 1
1 -> the '2's place is true, so 2
1 -> the '4's place is true, so 4
0 -> the '8's place is false, so 0
1 + 2 + 4 = 7.

https://docs.inductiveautomation.com/display/DOC81/binEnc

So you could, if you had truly mutually distinct bits, use binEnc to derive a single value that represents all possible combinations of your inputs.

1 Like

Thank you for the explanation, it helped me understand it greatly.

Are you able to use 2 case statements? true and false combined?

Case statements can only have one value to match on. In this case, you could probably use the binenc function, or break your logic into smaller pieces. Create some custom properties or tags with expressions that can represent certain logic, then combine those pieces into a final expression.

Also, if you need something to be false in one of your cases, just use the not operator ! to make it true.

I usually use binEnc to generate a state value, then use the Style Customizer to acheive the visual effect.

5 Likes