# Scripting a button press to turn on a PLC tag

**URL:** <https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964>\
**Category:** Ignition\
**Created:** [February 10, 2022, 5:46am UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964 "2022-02-10T05:46:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [February 10, 2022, 5:46am UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964/1 "2022-02-10T05:46:43Z")

</div>

Not sure if this is the right place. Trying to use the maker edition and a s7 1200 trainer kit to learn this software. Got everything connected finally and now I’m having a hard time trying to figure out how to link my tag to a button press. Do I need to script it? Not seeing an option to bind a button press like some articles suggest for the perspective vs the view I’m currently using. Sorry if this is a common question. Not sure how to format a button press for ignition quite yet. Thanks for any help

---

<div class="post-metadata">

**Author:** ![jhansen](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@jhansen](https://forum.inductiveautomation.com/u/jhansen)\
**Post date:** [February 10, 2022, 6:07am UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964/2 "2022-02-10T06:07:23Z")

</div>

You should be more specific about what you’re trying to achieve with the button press.

What is the tag’s data type?  
What do you want to happen when the button is pressed? “Linking” doesn’t really give us any information.

I can tell you that using a script is the most common way we see buttons used. You should configure a script on a button’s actionPerformed event. From the script, you can write a line of code to do a vast variety of things.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [February 10, 2022, 6:08am UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964/3 "2022-02-10T06:08:58Z")

</div>

Yep is a really basic question but this is why forums are for.  
Choose the button based on the kind of logic configured in the PLC, use one shoot button when sending a flag and waits a handshake.  
Most of the time you can use a standard button with a really simple script using [system.tag.writeBlocking](https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking).

Also explore the possibility to use tag bidirectional binging [Tag Bindings in Perspective](https://docs.inductiveautomation.com/display/DOC81/Tag+Bindings+in+Perspective#TagBindingsinPerspective-DirectTagBindingMode)

---

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [February 10, 2022, 6:21am UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964/4 "2022-02-10T06:21:18Z")

</div>

I want to on button press turn the bool value of a tag such as MX1.0 from a 0 to 1 then return back to 0. A momentary button. I’m using view and not perspective as this is the maker edition currently.

---

<div class="post-metadata">

**Author:** ![jhansen](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@jhansen](https://forum.inductiveautomation.com/u/jhansen)\
**Post date:** [February 10, 2022, 6:43am UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964/5 "2022-02-10T06:43:06Z")

</div>

This forum post gives a good solution;

> [@Perspective: Scripting a Momentary Button](https://forum.inductiveautomation.com/t/perspective-scripting-a-momentary-button/35684):
>
> Hey folks, Ignition 8.0.7 I’m trying to implement a momentary button in Perspective, but the feature doesn’t appear to be available. The One-Shot Button documentation states, [“If your PLC expects the HMI to reset the bit, use the Momentary Button.”](https://docs.inductiveautomation.com/display/DOC80/Perspective+-+One-Shot+Button) Since it seems as though the feature is not yet supported, does anyone have an example script for the button component that can reliably perform the Momentary function? I’m having a hard time replicating the function of the momentary button from Vi…

It's best to have a button set the value to 1 using a script. (Right click the button -\> Configure Events, then use the system.tag.writeBlocking() function to write to the tag). Then program the PLC to reset the value back to 0 after a given time.

If you want to do this only from ignition, refer to the forum post and use some form of sleep() or threading.Timer to write a 0 back to the tag after a specified time.

---

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [February 10, 2022, 4:27pm UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964/6 "2022-02-10T16:27:58Z")

</div>

so if they example was this, system.tag.writeBlocking(paths, values)  
Would writing system.tag.writeBlocking(MX1.0, 1) work to right a 1 value into the tag on button press?

---

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [February 10, 2022, 4:33pm UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964/7 "2022-02-10T16:33:28Z")

</div>

or is the path my tag name in ignition, such as if MX1.0 is assigned to an OPC tag called Switch 1 would it be (Switch 1, 1)

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [February 10, 2022, 6:07pm UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964/8 "2022-02-10T18:07:59Z")

</div>

This example is right out of the manual, its writing to 2 tags, but you can use this setup to write a single tag. Its not a bad idea to use this format vs directly coding your path and value int the writeBlocking operation.

```auto
# Create a list with the tag paths to be updated.
paths = ["[default]Folder/Tag_A","[default]Folder/Tag_B"]
 
# Create a list with the update values, one value for each path.
values = [1,2]
 
# Execute the write operation.
system.tag.writeBlocking(paths, values)

```

---

<div class="post-metadata">

**Author:** ![spencer.hillmick](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@spencer.hillmick](https://forum.inductiveautomation.com/u/spencer.hillmick)\
**Post date:** [November 14, 2025, 5:10pm UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964/9 "2025-11-14T17:10:29Z")

</div>

The absolute easiest way to do this, took me awhile to figure this out. create your plc tag import into IGN tag browser then drag and drop the tag on the desired Pushbutton. this creates the script for you

---

<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:** [November 16, 2025, 10:25pm UTC](https://forum.inductiveautomation.com/t/scripting-a-button-press-to-turn-on-a-plc-tag/55964/10 "2025-11-16T22:25:50Z")

</div>

Note, if this is Perspective, that using a script won’t automatically show errors to the user, so if a write fails the user won’t know.

If you instead bi-directionally bind the tag to a custom prop and use the button to write to that, then errors will be communicated e.g.

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