# Accessing Tags through button script

**URL:** <https://forum.inductiveautomation.com/t/accessing-tags-through-button-script/43927>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [March 1, 2021, 6:06am UTC](https://forum.inductiveautomation.com/t/accessing-tags-through-button-script/43927 "2021-03-01T06:06:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dvsagar95](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dvsagar95](https://forum.inductiveautomation.com/u/dvsagar95)\
**Post date:** [March 1, 2021, 6:06am UTC](https://forum.inductiveautomation.com/t/accessing-tags-through-button-script/43927/1 "2021-03-01T06:06:23Z")

</div>

Hi,

I have a button in which I am trying to change a tag value as per certain conditions. The tag values changes multiple times during the execution of the script. I am trying to see these variations on designer window . I have bound the tag value to a component . I am able to see only the final value on the component… (only after the execution of the button script completely). How to fix this problem? I want to see the changes on the tag value on the window.

Thank you.

---

<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:** [March 1, 2021, 1:12pm UTC](https://forum.inductiveautomation.com/t/accessing-tags-through-button-script/43927/2 "2021-03-01T13:12:07Z")

</div>

Does the value need to be a tag?

What I mean is this: Is there an external device that this script is changing?

Scripts execute in ms or less, so it doesn’t often make since to change a tag value multiple times throughout the script. This behavior is better served by a variable or window/component parameter.

---

<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:** [March 1, 2021, 1:22pm UTC](https://forum.inductiveautomation.com/t/accessing-tags-through-button-script/43927/3 "2021-03-01T13:22:54Z")

</div>

The gui won't update until after the script is finished. This is because the foreground thread of the script is the gui thread.

If this is a necessary thing to do, consider using @pturmel's later.py scripts.

> [@Update GUI via Asynchronous thread](http://forum.inductiveautomation.com/t/update-gui-via-asynchronous-thread/9666/3):
>
> Since this sort of thing pops up often, I created a set of wrappers that simplify this stuff, and allows you to directly use functions in your script modules. The wrappers take care of stuffing the arguments you supply into a temporary fuction’s default argument. For your case, try assignLater(). Nick’s example becomes: # In a script module in your project: import shutil def fileTransfer(label): path = system.file.openFile() newPath = "F:\NewFolder" shutil.copy2(path, newPath) sh…

---

<div class="post-metadata">

**Author:** ![dvsagar95](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dvsagar95](https://forum.inductiveautomation.com/u/dvsagar95)\
**Post date:** [March 1, 2021, 1:31pm UTC](https://forum.inductiveautomation.com/t/accessing-tags-through-button-script/43927/4 "2021-03-01T13:31:26Z")

</div>

Thank you for the response. There is no external device. I am working with secs gem ( the inbuilt simulator is used) where a button triggers a series of event runs. So I want to see a status change on a particular tag. So, it needs to be updated in accordance to the event run. The tag value is getting updated, but I can’t see it on the designer window as it shows only the final value ie. only after completing the whole script inside the button. Is there any way to fix this?

---

<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:** [March 1, 2021, 2:28pm UTC](https://forum.inductiveautomation.com/t/accessing-tags-through-button-script/43927/5 "2021-03-01T14:28:54Z")

</div>

> [@dvsagar95](#):
>
> I am working with secs gem ( the inbuilt simulator is used) where a button triggers a series of event runs.

You're going to have to do this on an Asynchronous thread. Take a look at the post of @pturmel's that @JordanCClark linked for a good discussion on this.

---

<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:** [March 1, 2021, 7:33pm UTC](https://forum.inductiveautomation.com/t/accessing-tags-through-button-script/43927/6 "2021-03-01T19:33:55Z")

</div>

> [@dvsagar95](#):
>
> Is there any way to fix this?

There is no bug in Ignition to fix. The error is in your use of an event routine for a long-running task. You cannot do this. (Not in any modern programming language--not just Ignition.) There are two approaches you can take for a problem like this:

1. Run the long task in an asynchronous thread, using the techniques in the linked topic to interact with the GUI, or

2. Break your task into many individual operations that run quickly as part of an appropriate trigger event, typically with an accompanying state machine.

In general, if you use any form of **sleep** or busy looping in an event routine, you've screwed up.

---

<div class="post-metadata">

**Author:** ![dvsagar95](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dvsagar95](https://forum.inductiveautomation.com/u/dvsagar95)\
**Post date:** [March 2, 2021, 3:36am UTC](https://forum.inductiveautomation.com/t/accessing-tags-through-button-script/43927/7 "2021-03-02T03:36:29Z")

</div>

Thank you. I will do that

---

<div class="post-metadata">

**Author:** ![dvsagar95](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dvsagar95](https://forum.inductiveautomation.com/u/dvsagar95)\
**Post date:** [March 2, 2021, 3:36am UTC](https://forum.inductiveautomation.com/t/accessing-tags-through-button-script/43927/8 "2021-03-02T03:36:44Z")

</div>

Thank you. I will try this

---

<div class="post-metadata">

**Author:** ![dvsagar95](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dvsagar95](https://forum.inductiveautomation.com/u/dvsagar95)\
**Post date:** [March 2, 2021, 3:37am UTC](https://forum.inductiveautomation.com/t/accessing-tags-through-button-script/43927/9 "2021-03-02T03:37:53Z")

</div>

Thank you. I will try with this method.
