I have an app where I need to change the Default Tag Group assignments for a many tags dispersed through multiple providers to another predefined tag group.
I though first, I'll search the tags for "Default" and do a find/replace. No, any other Tag Group is searchable but not Default.
Okay, so I'll do it externally, and export the tags to a Json file, and search/replace there. Also no, as when a Tag has a tag group of "Default", the Tag Group entry is not exported to Json.
Any way around this for globally searching/replacing the "Default" Tag group in tags, whether in one provider or across multiple providers?
My understanding is that default values for tags aren't exported (for all configuration parameters/properties, not just the tag group). I don't know of a quick way of doing it, but I'm guessing it could be done with scripting of the exported file to add a tag group if it doesn't exist.
This should do what you're looking for. You can use system.tag.read*() to get the values of any tag property default or otherwise. So you simply need to recursively browse your tags and write the value to any tag that isn't correct.
def updateTagGroup(parentPath,currentTagGroup,newTagGroup):
results = system.tag.browse(parentPath,{'tagType':'AtomicTag','recursive':True}).results
readPaths = ['{}.tagGroup'.format(result['fullPath']) for result in results]
tagGroups = {path:qv.value for path,qv in zip(readPaths,system.tag.readBlocking(readPaths))}
writePaths = [k for k,v in tagGroups.iteritems if v == currentTagGroup]
system.tag.writeBlocking(writePaths,[newTagGroup] * len(writePaths))
You may need to change the filter if UDT's are involved, but generally something like this will accomplish your goal.
Yes, I have....It identifies the tags, but then I imagined I would need scripting without brute force to change them.
Edit:
Did not realize that I could globally select and change attributes in the Reporting tool! That's a powerful feature. I knew you could edit individual tags within the report, but never tried selecting multiples.
Perfect. Fortunately, my UDTs are predefined with the tag groups I needed. It's the few tags someone drug in from the OPC browser that I need to find and change.