Updateing a tag's OPC path with script

I would like to update a single tag’s OPC item path with script but find that the new system.tag library no longer has the scripts that I was used to in version 7.

When I run the following script

#Updates the OPC path for the target tags
#project.admin.updateOPCPath
def updateOPCPath(folder):
	configs = system.tag.getConfiguration(folder, True)
	for tag in configs[0]['tags']:
		oldOpcPath = tag['opcItemPath']
		newOpcPath = oldOpcPath.replace('[Tunneler][Logix]','ns=1;s=[Tunneler][Logix,type=Boolean]')
		tag['opcItemPath'] = newOpcPath
	system.tag.configure(folder, configs, "o")

The existing tags inside the folder remain and new tags are created in a sub-folder. What is the preferred way of handling this? I have no problem iterating through each tag and making the change but the scripts available in version 8 pointed me toward changes to all the tags in the folder.

If I recall, you don’t need to specify the folder in system.tag.configure(), as the full path is part of the configurations you read.

system.tag.configure('', configs, "o")

I simply used the old scripts and it was a lot easier

#project.admin.updateOPCPath2
def updateOPCPath2(folder):
	tags = system.tag.browseTags(parentPath=folder, recursive=True, tagType="OPC")
	for tag in tags:
		oldOpcPath = system.tag.read(tag.path + '.opcItemPath').value
		newOpcPath = oldOpcPath.replace('[Tunneler][Logix]','ns=1;s=[Tunneler][Logix,type=%s]' % tag.dataType)
		system.tag.editTag(tagPath=tag.path, attributes={"OPCItemPath":newOpcPath})
1 Like