# Constructed Tag Path is Invalid

**URL:** <https://forum.inductiveautomation.com/t/constructed-tag-path-is-invalid/100327>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [December 30, 2024, 11:43pm UTC](https://forum.inductiveautomation.com/t/constructed-tag-path-is-invalid/100327 "2024-12-30T23:43:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Li](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@Eric\_Li](https://forum.inductiveautomation.com/u/Eric_Li)\
**Post date:** [December 30, 2024, 11:43pm UTC](https://forum.inductiveautomation.com/t/constructed-tag-path-is-invalid/100327/1 "2024-12-30T23:43:12Z")

</div>

Hello there,

I am trying to generate a valid tag path for the tagPaths parameter of system.tag.readBlocking function. The tag path I want to use is [Default]AI\_LT1.

The path does work If I generate the string in the following way

```python
path = "[Default]AI_LT1"
result = system.tag.readBlocking(path)

```

However, if I tended to generate the same path by combining one variable that contains a pre-defined value with a string component, the path is invalid then. There is the example code:

```python
tag_raw = self.props.selection.active.data[0]['displayPath']
tag_index = tag_raw.find('-')
tag_trimmed = tag_raw[:tag_index]

path = tag_trimmed + "AI_LT1"
result = system.tag.readBlocking(path)

```

* * *

In this case, tag\_trimmed is equal to [Default] and will display [Default]AI\_LT1 if print (path). However, it fails to read the proper tag content as what I type in the path = ''[Default]AI\_LT1" directly.

I tried some initial troubleshooting by using str (path) or .encode('utf-8') to return a string or unicode datatype but no luck.

Any idea why it happens? Thanks for the help!

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [December 30, 2024, 11:51pm UTC](https://forum.inductiveautomation.com/t/constructed-tag-path-is-invalid/100327/2 "2024-12-30T23:51:35Z")

</div>

Can you show us the text contained in `self.props.selection.active.data[0]['displayPath']` ? It is a little hard to follow what you are trying to achieve here.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [December 30, 2024, 11:55pm UTC](https://forum.inductiveautomation.com/t/constructed-tag-path-is-invalid/100327/3 "2024-12-30T23:55:26Z")

</div>

Add `print type(tag_trimmed)` to see if it is actually the type that you are expecting. Also try `print type(path)` to confirm its a string.

`system.tag.readBlocking` expects a list of tag paths. It allows you to pass a single string to avoid breaking projects from older versions that got upgraded. It might not like something about how you are constructing the string, so try using `result = system.tag.readBlocking([path])`

Also consider using java's string formatting to generate the path, ie:  
`path = "%sAI_LT1" % tag_trimmed`

---

<div class="post-metadata">

**Author:** ![Eric\_Li](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@Eric\_Li](https://forum.inductiveautomation.com/u/Eric_Li)\
**Post date:** [December 31, 2024, 12:23am UTC](https://forum.inductiveautomation.com/t/constructed-tag-path-is-invalid/100327/4 "2024-12-31T00:23:30Z")

</div>

Thanks for the rely!Tthe text contained in `self.props.selection.active.data[0]['displayPath'] is a PyUnicode with text [Default] - Alarm/Hi/Alarm:/alm:Alarm. After trimming, tag\_trimmed is then equal to [Default].

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [December 31, 2024, 12:26am UTC](https://forum.inductiveautomation.com/t/constructed-tag-path-is-invalid/100327/5 "2024-12-31T00:26:17Z")

</div>

Change this:  
`tag_index = tag_raw.find('-') `

to this:

`tag_index = tag_raw.find('-') -1`

You are including a space between the `[Default]` and the tag path.

---

<div class="post-metadata">

**Author:** ![Eric\_Li](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@Eric\_Li](https://forum.inductiveautomation.com/u/Eric_Li)\
**Post date:** [December 31, 2024, 12:27am UTC](https://forum.inductiveautomation.com/t/constructed-tag-path-is-invalid/100327/6 "2024-12-31T00:27:18Z")

</div>

Hello Ryan, thanks for the reply! the data type of path was PyUnicode. I tried use str(path) which supposes to return a PyString data type but still doesn't work. I will try the rest methods you mentioned later the.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [December 31, 2024, 12:29am UTC](https://forum.inductiveautomation.com/t/constructed-tag-path-is-invalid/100327/7 "2024-12-31T00:29:30Z")

</div>

Safer method might be to call `.strip()` on the result of the original trim, I can foresee someone not including that space between `[Default]` and the `-`.

---

<div class="post-metadata">

**Author:** ![Eric\_Li](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@Eric\_Li](https://forum.inductiveautomation.com/u/Eric_Li)\
**Post date:** [December 31, 2024, 5:54pm UTC](https://forum.inductiveautomation.com/t/constructed-tag-path-is-invalid/100327/8 "2024-12-31T17:54:43Z")

</div>

By applying either of your solutions @David_Stone @ryan.white and removing the space in between, the path is working properly now. Really appreciate the help!
