IA Scripting: system.tag.getAttribute requires TagProvider

My code seems to make sense and it looks like it would work fine:

tag = "MyTag"
if system.tag.exists(tag):
    doc = system.tag.getAttribute(tag, "Documentation")
    ...do stuff...

But I keep getting the error:

…‘MyTag’ does not exist…

Unless I change my code:

tag = "MyTag"
if system.tag.exists(tag):
    doc = system.tag.getAttribute("[MyTagProvider]" + tag, "Documentation")
    ...do stuff...

Sounds like exactly the behavior I’d expect when [MyTagProvider] != the internal provider named “default”

FWIW, Colby isn’t too happy with the implementation of system.tag.getAttribute(), so use it at your own peril. It’s still a part of 7.7 for backwards compatibility, but it’s been removed from the docs and intellihints to discourage its use. :slight_smile:

Sorry for picking on you Kathy but this is not the behavior I'd expect.

Here's why:

The system.tag.read() function uses the project's default SQLTag provider when no provider is provided. For example if my project's default tag provider is "MyProvider" and I use "system.tag.read('MyTag')" then the actual tag path used is "[MyProvider]MyTag".

Now if I use system.tag.getAttribute("MyTag", "Documentation") then it tries to use the "default" provider even though my project's default SQLTag provider is different. This is inconsistent.

I understand it probably needs to be this way in Ignition 7.7 for backward compatibility with the IA Labs Scripting Module.

The documentation for system.tag.getAttribute() does say that it will use the "default" provider if no provider is provided. That's a good thing.

Nick, perhaps I should have written “it’s the behavior I’d expect from the docs.” Sorry for not making that clear.

I understand now Kathy. Makes sense.

Kathy, you mentioned that the use of system.tag.getAttribute is discouraged. Is there another way to read the attributes of a tag? It seems that removing it from the docs is a bit strange if there is no alternative for doing something like

system.tag.getAttribute(tag.path, "ScanClass")

Is there another, safer way of doing this?

You should be able to read an attribute of a tag by using the system.tag.read command and using the “dot” notation to get it:

doc = system.tag.read("MyTag.Documentation").value

Yes, but unfortunately system.tag.read only gets you 3 of the tag attributes - value, quality, and timestamp.
I want access to all of the attributes which system.tag.getAttribute provides, but it isn’t documented and it’s use is ‘discouraged’.

There’s a list somewhere in the online documentation of all the tag attributes, but it’s almost impossible to find otherwise I’d post a link.

The attribute list is part of the IA Scripting user manual. (Find the “Tag Attribute” link under system.tag.getAttribute in the link I just posted.) You should be able to get any of the listed values simply by replacing the word “Documentation” in my previous code with any of those words.

Sorry, I didn’t read your code correctly. So to get attribute of tag one uses system.tag.read([tag path string]+’.’+[tag attribute string]).value

Thanks for helping me get there - and thanks for the link to the IA Scripting user manual.

There is probably an easier way to do this, but I was having a tough time reading parameters from a UDT in a Python-friendly format. I finally came up with: str(system.tag.read(‘tagname.ExtendedProperties’).value.local)
and then sliced that back to the dictionary that ‘parameters’ takes for tag.write.
If there is a syntax that gives me the dictionary directly, I would appreciate it, otherwise maybe this will save someone else the time it took to find the ugly approach above. :scratch: