# Creating Pipe Color Changes in a Circuit

**URL:** <https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [September 1, 2023, 11:28am UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665 "2023-09-01T11:28:09Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Heck](https://avatars.discourse-cdn.com/v4/letter/n/c57346/32.png) [@Nathan\_Heck](https://forum.inductiveautomation.com/u/Nathan_Heck)\
**Post date:** [September 1, 2023, 11:28am UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/1 "2023-09-01T11:28:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [September 1, 2023, 1:17pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/2 "2023-09-01T13:17:16Z")

</div>

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

```java
if({[default]SomeTag},'#00FF00','#FF0000')

```

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

```

---

<div class="post-metadata">

**Author:** ![Nathan\_Heck](https://avatars.discourse-cdn.com/v4/letter/n/c57346/32.png) [@Nathan\_Heck](https://forum.inductiveautomation.com/u/Nathan_Heck)\
**Post date:** [September 1, 2023, 2:14pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/3 "2023-09-01T14:14:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [September 1, 2023, 2:16pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/4 "2023-09-01T14:16:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Nathan\_Heck](https://avatars.discourse-cdn.com/v4/letter/n/c57346/32.png) [@Nathan\_Heck](https://forum.inductiveautomation.com/u/Nathan_Heck)\
**Post date:** [September 1, 2023, 2:19pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/5 "2023-09-01T14:19:39Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/2/32ffc95f0dfd5cfb8f8496dd4b691390480369d8.png)

---

<div class="post-metadata">

**Author:** ![Nathan\_Heck](https://avatars.discourse-cdn.com/v4/letter/n/c57346/32.png) [@Nathan\_Heck](https://forum.inductiveautomation.com/u/Nathan_Heck)\
**Post date:** [September 1, 2023, 2:20pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/6 "2023-09-01T14:20:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [September 1, 2023, 2:20pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/7 "2023-09-01T14:20:47Z")

</div>

I missed the vision tag on the post, you'll have to use the [color](https://docs.inductiveautomation.com/display/DOC81/color) expression function to return a color object.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [September 1, 2023, 2:24pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/8 "2023-09-01T14:24:53Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Nathan\_Heck](https://avatars.discourse-cdn.com/v4/letter/n/c57346/32.png) [@Nathan\_Heck](https://forum.inductiveautomation.com/u/Nathan_Heck)\
**Post date:** [September 1, 2023, 2:33pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/9 "2023-09-01T14:33:34Z")

</div>

ok, I will try this.

Thank you so much for the help.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [September 1, 2023, 2:55pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/10 "2023-09-01T14:55:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 1, 2023, 3:05pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/11 "2023-09-01T15:05:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nathan\_Heck](https://avatars.discourse-cdn.com/v4/letter/n/c57346/32.png) [@Nathan\_Heck](https://forum.inductiveautomation.com/u/Nathan_Heck)\
**Post date:** [September 1, 2023, 5:43pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/12 "2023-09-01T17:43:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 1, 2023, 6:03pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/13 "2023-09-01T18:03:39Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Nathan\_Heck](https://avatars.discourse-cdn.com/v4/letter/n/c57346/32.png) [@Nathan\_Heck](https://forum.inductiveautomation.com/u/Nathan_Heck)\
**Post date:** [September 1, 2023, 6:15pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/14 "2023-09-01T18:15:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nathan\_Heck](https://avatars.discourse-cdn.com/v4/letter/n/c57346/32.png) [@Nathan\_Heck](https://forum.inductiveautomation.com/u/Nathan_Heck)\
**Post date:** [September 1, 2023, 7:02pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/15 "2023-09-01T19:02:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [September 1, 2023, 7:08pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/16 "2023-09-01T19:08:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 1, 2023, 7:33pm UTC](https://forum.inductiveautomation.com/t/creating-pipe-color-changes-in-a-circuit/78665/17 "2023-09-01T19:33:01Z")

</div>

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