# Mapping a tag output from 1000 input values

**URL:** <https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483>\
**Category:** Ignition\
**Created:** [May 7, 2021, 4:32pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483 "2021-05-07T16:32:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 7, 2021, 4:32pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/1 "2021-05-07T16:32:48Z")

</div>

Is there a way to get the map transform on a tag so I can map all 1000 variations of a tag I am reading as input to multiple columns of outputs?  
And how so I easily access those outputs?

Here is what I am trying to do.

I am working in perspective on some pages.

I have a tag that gives me values 1-1000, a code

I need to interpret those values into either a 1, 2, 3, or 4.

I think that after I have these mapped, I will have to map another 1000 sets of text to the 1000 values.  
Might even have to map two sets.

So I thought the transform in the tag bindings is really nice as it has multiple columns for mapping.

I will need to place labels that read the text fields when these codes come up.  
I will need toggle some graphic visibilities when the 1-4 numbers come up.

I think I can possibly use the regular binding transform for this mapping.  
I just am not sure how it will work, or if there is a better way.  
Like I could hit the plus sign 1000 times and type each entry from my spreadsheet to the mapping.  
I just would prefer if I could do some copy and pasting instead.  
This is just the first of many machines.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 7, 2021, 4:45pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/2 "2021-05-07T16:45:26Z")

</div>

I’d probably put all this mapping logic into a script module and then use a script transform to just call those functions and ask for the transformed value.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 7, 2021, 5:11pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/3 "2021-05-07T17:11:20Z")

</div>

When you say script module, you mean a script in the scripting section?

And I am not sure how that would be structured.  
you mean like four long if conditions for the 1-4?  
if(code=(1 or 2 or 3…or N) then value =4

I am not sure how it would work for the strings.  
1000 if conditions to pair the code number to the text?

Use excel to concat the text all together to make the code fast?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 7, 2021, 5:14pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/4 "2021-05-07T17:14:29Z")

</div>

Maybe something like this:

```auto
code_map = {
	1 : 1,
	2 : 2,
	3 : 3,
	4 : 4,
	5 : 1,
	...
}

text_map = {
	1 : "text for 1",
	2 : "text for 2",
	3 : "text for 3",
	...
}

fun get_code(v):
	return code_map[v]

fun get_text(v):
	return text_map[v]

```

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 7, 2021, 5:23pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/5 "2021-05-07T17:23:18Z")

</div>

I want to test this.

Is this the way to test?  
I make a script in the project library with the mapping.  
I make a label for the text.  
In the label for the text, I bind the text with a script that calls my script with the tag for the code as a parameter.  
Then I see if the value is written to the label correct?

I think the spots I will need help with are like where to put the script.  
I think it goes in a folder in my project library.

I have many machines, so I am going to watch the script video again.  
I don’t see a way to make folders for my scripts to separate them for the machines.  
I see script packages, but I don’t know what that means so I will do some research and then test.

Thanks for the help. I will update when I have tested.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 7, 2021, 5:32pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/6 "2021-05-07T17:32:44Z")

</div>

I am mucking it up. In the script transform I had typed:

```
codescript get_code(value)
	return code_map[value]
return value

```

I named my script “codescript”  
in the script I copied

code\_map = {  
1 : 1,  
2 : 2,  
3 : 3,  
4 : 4,  
5 : 1,  
}

I am pretty certain that I am doing the call wrong.  
going to watch the videos again

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [May 7, 2021, 5:36pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/7 "2021-05-07T17:36:07Z")

</div>

> [@zacharyw.larson](#):
>
> ```auto
> codescript get_code(value)
> return code_map[value]
> return value
> 
> ```

It would be `codescript.get_code` instead of `codescript get_code` (period vs space), wouldn't it?

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 7, 2021, 5:37pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/8 "2021-05-07T17:37:26Z")

</div>

I didn’t make a get\_code() method.

I just have a code\_map dictionary

I messed it up lol

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 7, 2021, 6:08pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/9 "2021-05-07T18:08:35Z")

</div>

Okay, I found the most relevant video I think.  
[https://inductiveuniversity.com/videos/project-scripts/8.0](https://inductiveuniversity.com/videos/project-scripts/8.0)

Now I go back to my project script.

instead of

fun get\_code(v)

I instead write like

def get\_code(v)

?

* * *

then on my call in the script transform for the text of the label it is like:

project.codescript.get\_code(value)  
return value

?

* * *

I realize how silly codescript is as a script name. I promise I am using a different name more relevant to the actual machine.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 7, 2021, 6:18pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/10 "2021-05-07T18:18:18Z")

</div>

![Capture2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/5/e572f7a545db8db9ae04823d5cace5e843b7277b.png) ![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/2/e252e1af83c9e70cfbb4d8c20ddcf5f002cc0afd.png)

I have replaced “get\_code” with “get\_location”

whoops  
still broke though

I am doing multiple things wrong and trying to figure them out

I am pretty sure that my call is wrong, project is not recognized

---

<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:** [May 7, 2021, 6:23pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/11 "2021-05-07T18:23:23Z")

</div>

you can reduce the call to _machine1.get\_code(v)_. The ‘project’ is not necessary.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 7, 2021, 6:27pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/12 "2021-05-07T18:27:06Z")

</div>

omg it is alive

I was missing a colon and like you said, shortened to machine1.get\_location(value)

works now, I think

So I want to ask like when orginally it was said like

fun get\_code(v):

the “fun” was just something generic that an experienced ignition implementer would recognize as “def” right away?

or does “def” have certain characteristics and there are alternative keywords used there?

Thanks very much for the help you guys

---

<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:** [May 7, 2021, 6:28pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/13 "2021-05-07T18:28:44Z")

</div>

`fun` was probably a typo because Kevin usually writes Kotlin, which uses `fun` where Python uses `def`.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 7, 2021, 6:29pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/14 "2021-05-07T18:29:23Z")

</div>

thanks very much

---

<div class="post-metadata">

**Author:** ![drastura](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@drastura](https://forum.inductiveautomation.com/u/drastura)\
**Post date:** [May 13, 2021, 2:45pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/15 "2021-05-13T14:45:46Z")

</div>

Is that pattern always consistent? 1:1, 2:2, 3:3, 4:4, 5:1… 9:1, 10:2 … 487:4, 488:1 ?

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 13, 2021, 6:23pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/16 "2021-05-13T18:23:50Z")

</div>

I think you are asking me specifically about my dictionaries.  
I am making a dictionary for each of the different things associated with my code (number that means a lot of things) despite knowing that I could make a dictionary of lists for each code.

I have a code come in.  
I use the dictionaries for different sets strings and numbers.  
I some strings in different spots.  
I use the numbers to then change some images and references associated.  
I used some of the numbers different spots.

If you are asking in general, then a dictionary can be a dictionary of dictionaries, integers, strings, or lists.  
I think of it is kind of like linked lists.

Did you have some feedback for me or ideas you meant to suggest?  
Did I answer the question adequately?

---

<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:** [May 13, 2021, 8:26pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/17 "2021-05-13T20:26:21Z")

</div>

I think what @drastura is getting at is that if your pattern _is_ consistent, you can easily reduce it to a general algorithm; the modulo operator is your friend here, e.g.:

```auto
def get_code(i):
	return (i % 4) + 1

```

```auto
>>> for i in range(10):
... print(i, ":", get_code(i))
0 : 1
1 : 2
2 : 3
3 : 4
4 : 1
5 : 2
6 : 3
7 : 4
8 : 1
9 : 2

```

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 13, 2021, 8:56pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/18 "2021-05-13T20:56:05Z")

</div>

Thanks both of you.

That is really cool.

I wish it had been that way.

It is more categorically unique rather than a numeric pattern unfortunately.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 20, 2021, 8:14pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/19 "2021-05-20T20:14:11Z")

</div>

My script is in the project library.  
My call is on an object in the view.

So every client is going to check the condition of the machine and workout how the image on the view should look.

Is there a way to do that to reduce the workload?  
Is that something to really worry about or is it more typical?

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [June 2, 2021, 3:58pm UTC](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483/20 "2021-06-02T15:58:32Z")

</div>

I am thinking about receiving all my faults as a number and then using a dictionary to produce the text for the fault code.

I need help to understand how this will impact the server. If the dictionaries are in the project library, and the calls are on perspective pages, is that a lot of work for the server compared to another way?

Is it better to set the message to a tag first, and then use the tag in the views?  
If so, how do I pull that value from the dictionary into a tag?

[Next page](https://forum.inductiveautomation.com/t/mapping-a-tag-output-from-1000-input-values/46483.md?page=2)
