# How to code this expression , Using tags from plc

**URL:** <https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [May 29, 2025, 1:45pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822 "2025-05-29T13:45:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkantz](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@jkantz](https://forum.inductiveautomation.com/u/jkantz)\
**Post date:** [May 29, 2025, 1:45pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/1 "2025-05-29T13:45:20Z")

</div>

How too script :

1. If (tag is true)
2. Then (output tag) = true
3. else (output tag) = false

---

<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:** [May 29, 2025, 1:48pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/2 "2025-05-29T13:48:18Z")

</div>

The more detail you provide, the better the answer will be. Also, you have expression in the title, but script in the post, which one is it?

---

<div class="post-metadata">

**Author:** ![Leor\_Fishman](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@Leor\_Fishman](https://forum.inductiveautomation.com/u/Leor_Fishman)\
**Post date:** [May 29, 2025, 1:59pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/3 "2025-05-29T13:59:11Z")

</div>

...is there some reason the answer isn't just 'output tag = input tag'?

---

<div class="post-metadata">

**Author:** ![dillon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dillon/32/81537_2.png) [@dillon](https://forum.inductiveautomation.com/u/dillon)\
**Post date:** [May 29, 2025, 1:59pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/4 "2025-05-29T13:59:48Z")

</div>

Expression: [if | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/logic/if#syntax)

Scripting: [Python If Statement](https://www.w3schools.com/python/gloss_python_if_statement.asp)

---

<div class="post-metadata">

**Author:** ![jkantz](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@jkantz](https://forum.inductiveautomation.com/u/jkantz)\
**Post date:** [May 29, 2025, 2:00pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/5 "2025-05-29T14:00:10Z")

</div>

I wish to use script . So if a no contact(tag) is ON then turn on a output (tag).

How would i write this

---

<div class="post-metadata">

**Author:** ![dillon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dillon/32/81537_2.png) [@dillon](https://forum.inductiveautomation.com/u/dillon)\
**Post date:** [May 29, 2025, 2:00pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/6 "2025-05-29T14:00:14Z")

</div>

> [@Leor\_Fishman](#):
>
> output tag = input tag

Well, yes 😃

---

<div class="post-metadata">

**Author:** ![Leor\_Fishman](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@Leor\_Fishman](https://forum.inductiveautomation.com/u/Leor_Fishman)\
**Post date:** [May 29, 2025, 2:00pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/7 "2025-05-29T14:00:46Z")

</div>

output tag = input tag  
this would seem to be the simplest answer

---

<div class="post-metadata">

**Author:** ![jkantz](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@jkantz](https://forum.inductiveautomation.com/u/jkantz)\
**Post date:** [May 29, 2025, 2:01pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/8 "2025-05-29T14:01:29Z")

</div>

Thank You , Using If and else how would it look

---

<div class="post-metadata">

**Author:** ![Leor\_Fishman](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@Leor\_Fishman](https://forum.inductiveautomation.com/u/Leor_Fishman)\
**Post date:** [May 29, 2025, 2:01pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/9 "2025-05-29T14:01:59Z")

</div>

wait, why are you using a script, and why are you using ifs

---

<div class="post-metadata">

**Author:** ![jkantz](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@jkantz](https://forum.inductiveautomation.com/u/jkantz)\
**Post date:** [May 29, 2025, 2:03pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/10 "2025-05-29T14:03:39Z")

</div>

It is in there Logic choices (ignition)

---

<div class="post-metadata">

**Author:** ![Leor\_Fishman](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@Leor\_Fishman](https://forum.inductiveautomation.com/u/Leor_Fishman)\
**Post date:** [May 29, 2025, 2:05pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/11 "2025-05-29T14:05:25Z")

</div>

wait, sorry, trying to figure out the intent here. are you trying to figure out how to use if/else and use this as an example, or are you trying to solve this problem most effectively?

---

<div class="post-metadata">

**Author:** ![dillon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dillon/32/81537_2.png) [@dillon](https://forum.inductiveautomation.com/u/dillon)\
**Post date:** [May 29, 2025, 2:09pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/12 "2025-05-29T14:09:03Z")

</div>

If you want to create a new tag that references another, read [this documentation.](https://docs.inductiveautomation.com/docs/8.1/platform/tags/types-of-tags#reference-tags) You can use a reference or derived tag based on your needs.

If you are new to Ignition development, I would recommend [Ignition SCADA Courses Online | Inductive University](https://inductiveuniversity.com/). This is free 🙂

---

<div class="post-metadata">

**Author:** ![jkantz](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@jkantz](https://forum.inductiveautomation.com/u/jkantz)\
**Post date:** [May 29, 2025, 2:09pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/13 "2025-05-29T14:09:45Z")

</div>

Yes I have lots of code too write using \< \> + and if too turn on plc outputs .So I was looking for examples of how too write to output tags in a plc

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 29, 2025, 2:11pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/14 "2025-05-29T14:11:09Z")

</div>

Expressions do not write to arbitrary tags. They can be a result for an expression tag. If necessary, you can use my Integration Toolkit to RePublish the result to an OPC Item, but the general solution is a script, and only a script.

Be aware that writing to another tag within a source tag's `valueChange` event is dangerous, as writes can stall. (Unless it is a memory tag--those cannot stall.)

---

<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:** [May 29, 2025, 3:09pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/15 "2025-05-29T15:09:39Z")

</div>

The example you gave isn't great as the result is always the same as the input value.

In general pythons if..else syntacx looks like this:

```python
if condition == true:
    #execute action for true condition
elif nextCondition == true:
    #execute action for the next condition
else:
    #execute default action.

```

`elif` is short for `else if` this allows for chaining multiple conditions into a single if statement. Only one of the execution blocks (if, elif, or else) will execute.

In your stated example the script to read a tag, and write its value to an output tag could look like this:

```python
condtion = system.tag.readBlocking(['path/to/input/tag'])[0].value
outputValue = False

if condition == True:
    outputValue = condition
else:
    outputValue = False

system.tag.writeBlocking(['path/to/output/tag'][outputValue])

```

Since the output value is already False due to it's initialization, this can be simplified to:

```python
condtion = system.tag.readBlocking(['path/to/input/tag'])[0].value
outputValue = False

if condition == True:
    outputValue = condition

system.tag.writeBlocking(['path/to/output/tag'][outputValue])

```

And because the outputValue will always be the same as the condition, we can further simplify that to this:

```python
condtion = system.tag.readBlocking(['path/to/input/tag'])[0].value
system.tag.writeBlocking(['path/to/output/tag'][condition])

```

Which is why @Leor_Fishman said:

> [@Leor\_Fishman](#):
>
> output tag = input tag

However, in Ignition, this is sub optimum, and other methods should be used for this simple example.

For more complex situations the syntax of an if statement doesn't change. If you can provide more information about something that you are struggling to get working then we will be better able to provide concrete advice on how that should be handled.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 29, 2025, 3:14pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/16 "2025-05-29T15:14:47Z")

</div>

> [@pturmel](#):
>
> Be aware that writing to another tag within a source tag's `valueChange` event is dangerous, as writes can stall.

Err, what do you mean by this? 😨

---

<div class="post-metadata">

**Author:** ![Leor\_Fishman](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@Leor\_Fishman](https://forum.inductiveautomation.com/u/Leor_Fishman)\
**Post date:** [May 29, 2025, 3:15pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/17 "2025-05-29T15:15:50Z")

</div>

i assume valueChange is sync, and opc writes are blocking, so you can end up with stacking events...

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 29, 2025, 3:24pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/18 "2025-05-29T15:24:01Z")

</div>

But value change events just get added to the queue for the tag which then get processed in order (I assume?), no? From the value change event scripts that are currently running, they don't care how long they take\*, their code will always run from start to finish.

\*should be as fast as possible, but running too long may simply cause new events to be dropped; however the value change events that are running don't care, they just keep running until they've finished

---

<div class="post-metadata">

**Author:** ![Leor\_Fishman](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@Leor\_Fishman](https://forum.inductiveautomation.com/u/Leor_Fishman)\
**Post date:** [May 29, 2025, 3:25pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/19 "2025-05-29T15:25:14Z")

</div>

well yeah, but then you aren't guaranteed any sort of timing on when those writes are going to fire, even if you do have a guarantee as to order

---

<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:** [May 29, 2025, 3:26pm UTC](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822/20 "2025-05-29T15:26:25Z")

</div>

> [@nminchin](#):
>
> It doesn't matter how long they take\*

Not true, because there is a Thread pool across the gateway of size three (by default), so only 3 value change events can ever be processing at one time. This is seperate from the event queue specific to each tag (size 5 by default).

[Next page](https://forum.inductiveautomation.com/t/how-to-code-this-expression-using-tags-from-plc/106822.md?page=2)
