# Selecting multiple tags in component script

**URL:** <https://forum.inductiveautomation.com/t/selecting-multiple-tags-in-component-script/33843>\
**Category:** Ignition\
**Created:** [April 10, 2020, 10:41am UTC](https://forum.inductiveautomation.com/t/selecting-multiple-tags-in-component-script/33843 "2020-04-10T10:41:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcg](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@marcg](https://forum.inductiveautomation.com/u/marcg)\
**Post date:** [April 10, 2020, 10:41am UTC](https://forum.inductiveautomation.com/t/selecting-multiple-tags-in-component-script/33843/1 "2020-04-10T10:41:43Z")

</div>

Hi! i’m beginner to ignition, i just want to ask if there’s a way to select multiple tags in button’s component script. i use event handlers “mouseclicked” but i can only control 1 tag

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [April 10, 2020, 10:47am UTC](https://forum.inductiveautomation.com/t/selecting-multiple-tags-in-component-script/33843/2 "2020-04-10T10:47:11Z")

</div>

Instead of using the ‘Set Tag Value’ tab, use the ‘Script Editor’ tab. Here you can create whatever you want. Start with the ‘Set Tag Value’ and add your first tag. Then click on ‘Script Editor’ and the code for that instruction will be displayed. Then just copy for any additional tags.

---

<div class="post-metadata">

**Author:** ![marcg](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@marcg](https://forum.inductiveautomation.com/u/marcg)\
**Post date:** [April 10, 2020, 10:52am UTC](https://forum.inductiveautomation.com/t/selecting-multiple-tags-in-component-script/33843/3 "2020-04-10T10:52:01Z")

</div>

Hi sir, first thanks for replying,  
this is the instructions, can you give me an example if how i’ll write if i want to add machine2/state tag  
system.tag.writeBlocking([’[default]Machine/Machine1/State Tag’], [value])

# The square brackets around [tagpath] and [value] create a list containing

# those items, because the system.tag.writeBlocking function requires you to

# specify those arguments as a list.

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [April 10, 2020, 10:53am UTC](https://forum.inductiveautomation.com/t/selecting-multiple-tags-in-component-script/33843/4 "2020-04-10T10:53:36Z")

</div>

like this:

system.tag.writeBlocking([’[default]Machine/Machine1/State Tag’, ’[default]Machine/Machine2/State Tag’], [value, value2])

The above is more efficient as it does it in one instruction, but you could also copy the whole instruction like this:  
system.tag.writeBlocking([’[default]Machine/Machine1/State Tag’], [value])  
system.tag.writeBlocking([’[default]Machine/Machine2/State Tag’], [value2])

---

<div class="post-metadata">

**Author:** ![marcg](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@marcg](https://forum.inductiveautomation.com/u/marcg)\
**Post date:** [April 10, 2020, 11:18am UTC](https://forum.inductiveautomation.com/t/selecting-multiple-tags-in-component-script/33843/5 "2020-04-10T11:18:58Z")

</div>

oh it works thanks, but how do i define the value 2? when i press button it controls same value  
what i mean is to control the value dynamically by using a paramater {MachineNumber} example

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [April 10, 2020, 11:37am UTC](https://forum.inductiveautomation.com/t/selecting-multiple-tags-in-component-script/33843/6 "2020-04-10T11:37:26Z")

</div>

If you have a MachineNumber Custom Property on the Button you could use this:

```auto
tagPath='[default]Machine/Machine%d/State Tag' % (event.source.MachineNumber)
system.tag.writeBlocking([tagPath], [value])

```

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [April 10, 2020, 11:41am UTC](https://forum.inductiveautomation.com/t/selecting-multiple-tags-in-component-script/33843/7 "2020-04-10T11:41:00Z")

</div>

If you’re reading the machine number from a tag you will need something like this:

```auto
machineNumber = system.tag.readBlocking(['[default]MachineNumber'])[0].value
tagPath='[default]Machine/Machine%d/State Tag' % (machineNumber)
system.tag.writeBlocking([tagPath], [value])

```

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [April 10, 2020, 11:47am UTC](https://forum.inductiveautomation.com/t/selecting-multiple-tags-in-component-script/33843/8 "2020-04-10T11:47:31Z")

</div>

You could also do this without any code by adding two Custom Properties to the button:  
MachineNo - Bound to the MachineNumber tag or property  
MachineState - Bound to an Indirect tag of the Machine State:

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

Then just use the Set Property on the button:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/921ff9bd13e4f0c5c90a44f76978285c7f986de0.png)

---

<div class="post-metadata">

**Author:** ![marcg](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@marcg](https://forum.inductiveautomation.com/u/marcg)\
**Post date:** [April 10, 2020, 12:36pm UTC](https://forum.inductiveautomation.com/t/selecting-multiple-tags-in-component-script/33843/9 "2020-04-10T12:36:42Z")

</div>

Hi sir thanks for all the help, ahm  
machineNumber = system.tag.readBlocking([’[default]MachineNumber’]) - on this part should i put the path of my tag “machinenumber” here?

---

<div class="post-metadata">

**Author:** ![marcg](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@marcg](https://forum.inductiveautomation.com/u/marcg)\
**Post date:** [April 10, 2020, 12:46pm UTC](https://forum.inductiveautomation.com/t/selecting-multiple-tags-in-component-script/33843/10 "2020-04-10T12:46:29Z")

</div>

Haha i used this and paste “machineNumber” tag path then it worked.

Thank you so much sir David
