# Reading Tag Names

**URL:** <https://forum.inductiveautomation.com/t/reading-tag-names/96453>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [September 25, 2024, 6:59pm UTC](https://forum.inductiveautomation.com/t/reading-tag-names/96453 "2024-09-25T18:59:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Joe\_Alcide](https://forum.inductiveautomation.com/u/Joe_Alcide)\
**Post date:** [September 25, 2024, 6:59pm UTC](https://forum.inductiveautomation.com/t/reading-tag-names/96453/1 "2024-09-25T18:59:13Z")

</div>

Hi!

I am looking to be able to read the name of a tag if its value meets a condition:

```python
Taglist = [
		"Tag 1",
		"Tag 2",
		"Tag 3",
		"Tag 4"
	]
Tag_path2 = [
		"Tag 1",
		"Tag 2",
		"Tag 3",
		"Tag 4"
	]

Tag_Read= system.tag.readBlocking(Taglist)
Tag2_Read= system.tag.readBlocking(tag_path2)
for i in range(len(Taglist)):
	mode = Tag_read[i].value
	name = Tag_read[i].name
	split = name.split()
	fixedname = split[1]
	if mode == "OPEN":
		Thing += Thing1 + Thing2 
		comparator= system.tag.readBlocking(tag_path2) 
		for j in range(len(tag_path2)):
			linetk = comparator[j].value 
			line = comparator[j].name
			linesplit = line.split()
			runline = linesplit[0] + linesplit[1]
			if fixedname == linetk:

```

Obviously you can''t do system.tag.read the name component of a tag. Is there any other way of reading a name of a tag, so you can use it in comparisons? Any help would be appreciated, thanks!

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [September 25, 2024, 7:15pm UTC](https://forum.inductiveautomation.com/t/reading-tag-names/96453/2 "2024-09-25T19:15:28Z")

</div>

Perhaps I'm misunderstanding your intent, but since you're iterating over a range equivalent to `len(TagList)`, couldn't you just access the tag name _(tag path)_ in your original list? With

```python
name = Taglist[i]

```

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [September 25, 2024, 7:20pm UTC](https://forum.inductiveautomation.com/t/reading-tag-names/96453/3 "2024-09-25T19:20:11Z")

</div>

You could also zip these like:

```python
for qualVal, tagPath in zip(Tag_Read, Taglist):
    mode = qualVal.value
    name = tagPath

```

---

<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:** [September 25, 2024, 8:42pm UTC](https://forum.inductiveautomation.com/t/reading-tag-names/96453/4 "2024-09-25T20:42:41Z")

</div>

There's a lot of things that might "work" but are definitely not ideal about the code you've written.

Can you take a step back and describe what you're trying to do in more detail? Where are you running this script/what is it reacting to, what do you want it to do, how often do you want it to run, that kind of thing.

---

<div class="post-metadata">

**Author:** ![vtran](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vtran](https://forum.inductiveautomation.com/u/vtran)\
**Post date:** [September 25, 2024, 8:42pm UTC](https://forum.inductiveautomation.com/t/reading-tag-names/96453/5 "2024-09-25T20:42:55Z")

</div>

You might be able to use the **Tag Report Tool** to generate a script for this. Simply add a Tag Path filter and add a property condition to match with what you want.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/c/9cb56570a96c7126b4c5e5ca03a549d25cb45cd5.png)  
Then you can **Copy as Scipt** to have something like the following

```python
provider = 'default'
limit = 100

query = {
  "options": {
    "includeUdtMembers": True,
    "includeUdtDefinitions": False
  },
  "condition": {
    "path": "*tag*",
    "attributes": {
      "values": [],
      "requireAll": True
    },
    "properties": {
      "and": [
        [
          "value",
          "Equal",
          "[1, Good, Wed Sep 25 13:38:13 MST 2024 (1727296693093)]"
        ]
      ]
    }
  },
  "returnProperties": [
    "name",
    "tagType",
    "quality"
  ]
}

# Limited to 100 rows. Use continuationPoint functionality to continue from last result, 
# or remove limit for full results.
results = system.tag.query(provider, query, limit)

```

Adjust if needed. The default limit is 100.  
Then you can extract the tag names from the `results` output

---

<div class="post-metadata">

**Author:** ![Keegan\_Stewart](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/keegan_stewart/32/67844_2.png) [@Keegan\_Stewart](https://forum.inductiveautomation.com/u/Keegan_Stewart)\
**Post date:** [September 25, 2024, 8:53pm UTC](https://forum.inductiveautomation.com/t/reading-tag-names/96453/6 "2024-09-25T20:53:12Z")

</div>

The best way that found to pull the name from a tag is by parsing the value by "/". Then only have it only return the last part of your path.

---

<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:** [September 25, 2024, 11:02pm UTC](https://forum.inductiveautomation.com/t/reading-tag-names/96453/7 "2024-09-25T23:02:42Z")

</div>

To explicitly state it:

```python
tagPath = '[default]this/is/my/tag'
tagPath.split('/')[-1]

```

---

<div class="post-metadata">

**Author:** ![Joe\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Joe\_Alcide](https://forum.inductiveautomation.com/u/Joe_Alcide)\
**Post date:** [September 25, 2024, 11:26pm UTC](https://forum.inductiveautomation.com/t/reading-tag-names/96453/8 "2024-09-25T23:26:13Z")

</div>

This gives you the .value, not the tag path.

---

<div class="post-metadata">

**Author:** ![Joe\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Joe\_Alcide](https://forum.inductiveautomation.com/u/Joe_Alcide)\
**Post date:** [September 25, 2024, 11:28pm UTC](https://forum.inductiveautomation.com/t/reading-tag-names/96453/9 "2024-09-25T23:28:50Z")

</div>

Nevermind, this worked, thank you!
