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

Hello
The system.tag.writeAsync() only work to write the member value of UDT if I manually check the green override circle in Tag properties, otherwise it can’t write anything to it.
How I make a properties editable in script? so I can use system.tag.writeAsync()

You can use system.tag.configure to set and clear (set to None) overrides, rather than manually enabling the override.

The problem is I can’t access to atomicTag easily with system.tag.configure() . Creating JSON structure is really hard for folder in folder kind of UDT.
Could you please show me this in code? There is no such thing as overrides in docs.
If I have this fullpath : [default]DPB/PI05051/CMD/OVR
which
DPB/ is folder
PI05051 is UDT
CMD is folder in UDT
OVER is atomicTag.

I just tested this on 8.0.9:
image
Tag configured with no overrides:

def callback(result):
	print result
system.tag.writeAsync(['[default]DPB/PI05051/CMD/OVR.Enabled'],[False],callback)

After running that script, Enabled override is on and it is set false:


The override was set automatically with the tag write.

Are you on a different version, or is there something different in what you’re trying than in the test above?

1 Like

This clears the override, returning the value to UDT defined value:


baseTagPath = '[default]DPB/PI05051/CMD'
tags = []
collisionPolicy = 'o'
tags.append({
	'name': 'OVR',
	'overrides': {'Enabled':None}
})
system.tag.configure(baseTagPath, tags, collisionPolicy)

What’s strange though, is replacing None with False does not work to set OVR.Enabled to false. EDIT: See this post below for setting overrides.

1 Like

Thanks I'm in version 8.0.6. and did exactly as you show here. So it is a bug in 8.0.6.
Thanks again

You bet; it looks like there’s also a bug in 8.0.9 with setting overrides with system.tag.configure. If we write False to OVR.Enabled with system.tag.writeAsync as shown above so it’s overridden to false, system.tag.configure will then clear the override if we set it to None (as expected). But if we use system.tag.configure to set that override to True, it also clears the override (instead of overriding to true as expected). And I haven’t found a way to get system.tag.configure to do anything when trying to configure OVR.Enabled to False. In all cases system.tag.configure returns[Good], but the only case where it behaves as expected is setting the override to None.

EDIT: See this post below for the correct way to set overrides with system.tag.configure.

Could you replace your overrides code with baseTag = '[default]DPB/PI05051'?
I need this because in some cases the CMD folder is another UDT inside the first level UDT or there multiple level of deep in structure.
How should modify tags.append() to go the last level and change overrides?

It would be handy if you could configure multiple levels at once, but I believe system.tag.configure requires that all but the final tag name is part of the base path. So if you need to configure things at multiple levels within the UDT you’ll need to do it with a separate system.tag.configure for each level.

EDIT: This is incorrect. See this post below for the correct way to set overrides at various nesting levels with system.tag.configure, and see this post further below for a function that builds the nested structure for you.

1 Like

but your code doesn’t work. Did you

baseTagPath = '[default]DPB/PI05051/CMD'
tags = []
collisionPolicy = 'o'
tags.append({
	'name': 'OVR',
	'overrides': {'Enabled':None}
})
system.tag.configure(baseTagPath, tags, collisionPolicy)

The first line cause ignition create folder called CMD in stead of editing member.

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