Overriding Properties in UDT Instances by system.tag.writeAsync()

That code is for editing [default]DPB/PI05051/CMD/OVR.Enabled when the tag already exists. If it doesn't already exist, system.tag.configure will create the base path in folders as you note because it doesn't have any information to tell it to do something else with the levels above.

To create this structure including UDT with system.tag.configure, you'd need to first call system.tag.configure to create the UDT instance PI05051 at base path [default]DPB, and then call it again as above to configure the override on [default]DPB/PI05051/CMD/OVR.Enabled (although as noted above, there seems to be a bug with setting overrides via system.tag.configure in 8.0.9; using system.tag.writeAsync/Blocking works).

EDIT: The second parapgrah above is incorrect. See this post below for the correct way to set overrides at various nesting levels with system.tag.configure (you can create the tag and set overrides at various nesting levels all in one system.tag.configure call), and see this post further below for a function that builds the nested structure and sets a nested property override based on supplied path.

1 Like

I create the UDT before.

I install v8.0.9 but the system.tag.writeAsync() still doen’t work for me even it return Good. ;(

is there any security trick here?

Oh I find the problem. Your code only work in perspective session not vision.

Yeah, that sounds like a security thing. All the testing I did was via script console in Designer. You should be able to get it working in Vision with the Tag Editing permission shown below enabled:
image
EDIT: This applies to system.tag.configure; it shouldn’t apply to system.tag.writeAsync, though there may be some other permission affecting that.

1 Like

Interestingly After the first time I create UDT instance the system.tag.writeAsync doesn't work but if I manually override a property apply and change to disable override again the system.tag.writeAsync will work.
Did you test it? Create the UDT and immediately call system.tag.writeAsync(). It doesn't work.

# Path  | tagName | dataType | typeId | OPCServer | OPCItemPath | TagType | EngLow | EngHigh | HH | H | L  | LL |
#  [0]  |   [1]   |   [2]    |   [3]  |    [4]    |     [5]     |    [6]  |   [7]  |   [8]   | [9]|[10|[11]|[12]|
#DPB/CM | PI3423  | Boolean  |        |           |             | OPC     |
#       | PMP1/Ru | Float4	 | PMP    |           |             | Memory  |

# Prompt user to open a csv file and read it
filePath = system.file.openFile()
csv = system.file.readFileAsString(filePath,"UTF-8")
# Split it by linefeeds into a list (each line is a list member) 
rows = csv.splitlines()
# Remove csv header row
rows.pop(0) 

i = 0 # Loop counter for how many tags created
# Go through the rest of the data in csv row by row and create tag
for row in rows:

	# split row by column to access each column
	column = row.split(',')
		
	# Get tag Path folder
	if column[0] != '':
		tagPath = column[0]+'/' # need / to combine with tagName
	else:
		tagPath = '' 

	# Get tag name and split atomictag from it
	tagName = column[1].split('/')[0]
	
	# Get dataType like float4, int3, boolean, ...
	dataType = column[2]

	# Get typeId (UDT Type) 
	typeId = column[3]

	if typeId != "": # we have atomicTag if it is UDT
		member = column[1][column[1].find('/')+1:]
	
	# Get opcServer usually indicate the Location_device
	opcServer = column[4]

	# Get opcItemPath, 	
	#opcItemPath = column[5].replace('DB26.','DB26,') #Siemens driver accept DB26,X0.0 not .
	opcItemPath = column[5]
	
	# Get tagType, not use for UDT onlyu for Normal Tag
	tagType = column[6]
	
	# Get Parameters, only if we have at least one valid parameters otherwise don't overwrite anything
	parameters = {} # make empty dictionary
	
	if column[7] + column[8] + column[9] + column[10] + column[11] + column[12] != '': # we have some thing for parameters
		parameters['EngLow'] = column[7]
		parameters['EngHigh'] = column[8]
		parameters['HHSP'] = column[9]
		parameters['HSP'] = column[10]
		parameters['LSP'] = column[11]
		parameters['LLSP'] = column[12]

	i += 1
	fulltagPath = tagPath + tagName + '/' + member
	print 	str(i) +': ' + fulltagPath
	# ********************************************************
	# Create UDT Tag
	# ********************************************************
	if typeId != '':
		tag = {
			"name": tagName,         
			"typeId" : typeId,
			"tagType" : "UdtInstance",
			"parameters" : parameters
#			"tags" : [
#	           	{
#	           	"name" : member,
#	           	"tagtype" : "AtomicTag",
#	           	"opcServer" : opcServer,
#	           	"opcItemPath" : opcItemPath
#	           	}
#            ]
		}
		system.tag.configure(tagPath, [tag], 'm')
		
		def callback(result):
			print result
		
		system.tag.writeAsync([fulltagPath + '.opcItemPath'],[opcItemPath],callback)
		system.tag.writeAsync([fulltagPath + '.opcServer'],[opcServer],callback)
		
	# ********************************************************
	# Create Normal Tag
	# ********************************************************
	else:
		tag = {
	            "name": tagName,           
	            "opcItemPath" : opcItemPath,
	            "opcServer": opcServer,
	            "valueSource": tagType, # opc, memory, ...
	            "dataType" : dataType, # Float4, Boolean, 
	            "tagGroup" : "Default"
	        }
		system.tag.configure(tagPath, [tag], 'm')	        

Please see this video this. I use 8.0.9.

The weird behaviour with overrides bothered me so I came back to this. I believe the below example will do what you are aiming for–and won’t require multiple system.tag.configure calls to override nested properties.

# Create UDT instance with OVR member disabled.
# The tags lists are only included to add the override to the UDT member.
# Add additional key:value pairs to any level to add more overrides.
collisionPolicy = 'o'
tags = [
	{'tags':
		[
			{'tags':
				[
					{'enabled': False,
					'name': 'OVR'
					}
				],
			'name': 'CMD'
			}
		],
	'tagType': 'UdtInstance',
	'name': 'PI05051',
	'typeId': '_Test/Test'
	}
]
system.tag.configure("[default]DPB", tags, collisionPolicy)

If you want to add an override or more to existing tags:

# Enable OVR member via override.
# Use names for path and properties to override only. Use merge collision policy.
collisionPolicy = 'm'
tags = [
	{'tags':
		[
			{'tags':
				[
					{'enabled': True,
					'name': 'OVR',
					}
				],
			'name': 'CMD'
			}
		],
	'name': 'PI05051',
	}
]
system.tag.configure("[default]DPB", tags, collisionPolicy)

To remove an override, you could recreate the tag without the override using overwrite collision policy. Or this works:

# Remove an override from an existing tag.
collisionPolicy = 'o'
tags = [
	{'name': 'OVR',
	'overrides': {'Enabled':None}
	}
]
system.tag.configure('[default]DPB/PI05051/CMD', tags, collisionPolicy)

Sorry for the misdirection earlier–most of my experience with UDTs was with system.tag.addTag and there are clearly some differences with system.tag.configure, particularly around overrides.

Thanks. I still don't know I can the structure you mention above on fly in script. You create that structure manually Not by coding. Also you know that "CMD" level is tagType = folder. There is case which it is another UDT fro example.
I want to read a csv file which each row has fullTagPath and write something into opcItemPath of that tagPath.
So I believe using system.tag.configure() is titally useless here.
The system.tag.writeAsync() after creating the UDT tag by system.tag.configure() is want I want, but as you see in video the system.tag.writeAsync() doesn't work.
It seems it is bug.

Yes, I haven’t played more with system.tag.writeAsync, but noticed the same behaviour you did. It does work later on a tag that hasn’t been touched since creation, so it seems like it may just need a delay.

For the overrides, the type of CMD doesn’t matter; I inadvertently left that folder type in the first code block, but removing it doesn’t change anything. As long as the UDT definitions are pre-existing, creating the top level UDT tag will create everything under it. The nested lists and dictionaries only need the tag name at each level to define the path to the property key/value pair(s) to override.

Here’s a function you can use instead of system.tag.writeAsync to override properties. It builds the structure in the second code block example in earlier post above, and works for any nesting depth.

# Override a property at variable nesting within a UDT.
# Provide basePath that UDT is in, and path to property from there.
# Property path must contain the property's tag name (i.e. "OVR.enabled", not "enabled").
def tagPropertyOverride(basePath, tagPropertyPath, overrideValue):
	names = tagPropertyPath.replace('.','/').split('/')
	# Cut property from names.
	overrideProperty = names.pop(len(names)-1)
	tags = None
	# Build structure from deepest nesting level up.
	for name in reversed(names):
		if tags is None:
			# This is the innermost level; include property override.
			tags = [{'name':name, overrideProperty:overrideValue}]
		else:
			# Nest last level inside this one and add name for this level.
			tags = [{'name':name, 'tags':tags}]
	# Merge this override with existing tag.
	system.tag.configure(basePath, tags, 'm')

tagPropertyOverride('[default]DPB', 'PI05051/CMD/OVR.enabled', False)

EDIT: For future readers, if you don’t need the ability to work to various nesting depths for a particular base path, see this post for a simpler solution (direct replacement for tag write) to override a property at a path.

4 Likes

I don’t know how to thank you. You save me. What a clever idea.
:pray::pray::pray::pray::pray::pray::pray:

The system.tag.writeAsync() does work only if the key is exist in tag struct. Because Ignition doesn’t include any properties that use default value from it’s UDT, so the property doesn’t exist and system.tag.writeAsync() doesn’t work. The override cause that key, value include in tag struct and after that system.tag.writeAsync().
Do you believe this is a bug? In v7.9 the system.tag.write() did work.

1 Like

The inability to write to (rather than configure) default properties does sound like a bug–or at least a loss of capability–caused by the changes to the tag system.

1 Like

Hi witman
Could you please modify your function so I can toggle alarms enable of a tag.
For example I have udt : PT2323/PV
The PV/Alarms/Hi.enable
The /Alarms/Hi.enable is not path so the your function will not work.
I used to toggle alarm enable with system.tag.wrtie(“PT2323/PV/Alarms/Hi.enable”, True) in v7.9 but as before it doesn’t work in v8.

Would this work for you?

def overrideAlarmConfig(tagPath, alarmName, alarmProperty, value):
	config = system.tag.getConfiguration(tagPath)[0]
	for alarm in config['alarms']:
		if alarm['name'] == alarmName:
			alarm[alarmProperty] = value
			break
	basePath = tagPath.rsplit('/',1)[0]
	system.tag.configure(basePath, config, 'm')

overrideAlarmConfig("[default]PT2323/PV", "Hi", "enabled", True)
2 Likes

It looks like the inability to write to these may be resolved in 8.0.12 (I haven't tested):

1 Like

I’ve been combing through these threads searching for a way to disable an override for only a single property of a udt tag instnace. I have some tags that have their opcItemPath overridden, and I want to disable the override for that propety only, while keeping some others overridden.

tag = {
'name':tagname,
'overrides': {'opcItemPath':None}
}	

system.tag.configure(cfg_tag_path, [tag], 'o')

The code above disables all override of my instance tag, and also creates a custom object within my instance tag: overrides = {’‘opcItemPath’:None}

@tmahaffey @witman

Found this thread from searching around, trying to do the same thing.

Have you (or anyone) ever found a solution? I get the exact same behavior as you.

'overrides': {'Enabled':None} })

The syntax you guys shared does remove override, but also creates a custom property leftover.

This will remove an override, but unfortunately turns all the non-overridden values included in system.tag.getConfiguration into overrides. Supply a tag path in place of tagPath.

# Get tag config.
cfg = system.tag.getConfiguration(tagPath)[0]
# Remove opcItemPath key.
cfg.pop('opcItemPath', None)
# Get base path.
basePath = tagPath.rsplit("/",1)[0]
# Overwrite tag with cfg that we removed key from.
system.tag.configure(basePath, cfg, 'o')

If system.tag.getConfiguration didn’t return non-overridden values, the above would work without adding overrides.

If you want to remove all overrides from a tag, this works (supply a tag path in place of tagPath):

basePath, name = tagPath.rsplit("/", 1)
cfg = {'name': name}
system.tag.configure(basePath, cfg, 'o')
2 Likes

Has anyone figured out how to remove overrides for just certain tag properties and not the entire tag using scripting? Is that possible?

I haven’t tried and there might be an easier way I’m not aware of, but… I expect this could be done by comparing the UDT instance with the UDT template and removing the override node as well as nodes that weren’t overridden from template but will turn into overrides if you write them back with system.tag.configure. Unless I’m missing something, system.tag.getConfiguration really should not return non-overridden values from UDTs. That would make this easy and the code in my previous post would accomplish what you’re looking for.