Reading Tag Names

Hi!

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

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!

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

name = Taglist[i]

You could also zip these like:

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

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.

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.


Then you can Copy as Scipt to have something like the following

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

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.

To explicitly state it:

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

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

Nevermind, this worked, thank you!