KeyError In Script

Hi there,

I"m getting an error in a script that I imported from a running HMI System into a development system. The script itself is being called as required but I am getting an error that says “KeyError: FACEPLATES_ADE_00”. I have the dataset FACEPLATES_ADE_00 created in my project, so I’m not sure how to go about testing what is wrong.

Here is the set of script that is throwing the error:

if action == "OPEN":
		for ea in dict_faceplates['FACEPLATES_ADE_00']: # 	# Iterate the globally defined dataset
			if ea['UDT'] == udtParent:
				# General Parameters
				fpParam['SelectedTab'] = 0
				fpParam['DeviceTag'] = event.source.DeviceTag
				# Add any additional faceplate specific parameters below here
				if (ea['UDT'] == "ADE_00/ADE_E_HIC") or (ea['UDT'] == "ADE_00/ADE_E_PID"): # Append additional parameter for PID blocks
					if not event.source.DeviceTagAI == '':
						if tag+'/HMI/CFG/DeviceTagAI' ).value == '':
				# Call the window activate command
				SYS_02.GlobalFaceplateActivate(ea['fpName'], ea['fpDest'], fpParam, action="SWAP")
				return True

Any help would be appreciated. I’m not really clear on where to start troubleshooting this.

This isn’t the entire script, but the KeyError is being thrown because the dict_faceplates variable (presumably, a dictionary) is missing the key 'FACEPLATES_ADE_00'. I couldn’t really tell you why that is, but that’s the root of your problem. Check for anything overwriting the dict_faceplates variable elsewhere in the script.

HI Paul,

I’m seeing, in order, the follwoing writes to dict_faceplates
dict_faceplates = {} # Dictonary to hold Faceplate Associations
dict_faceplates[] = system.dataset.toPyDataSet( )

There’s not much to go on with that, but I assume this script is being called once on the startup of the entire system, and I haven’t initiated that yet. I’ll start on that initialization route and see what happens. Thanks for the quick response.

1 Like

It’s either the initialization (likely) or isn’t exactly the literal string 'FACEPLATES_ADE_00'.

PGriffith beat me to it but I’ll keep this here anyways. Have you tried just looping through the dictionary keys and printing them to the console to make sure the key you are looking for is actually in there and exactly how you have it typed (lowercase vs uppercase, etc)?

Yeah, i was able to print those to console. It found the exact tagname, but I’ll take another look tomorrow. Since it is actively running on a SCADA system right now, I am willing to bet the code it fine, it’s probably just how I imported everything piecemeal and didn’t just restore the gateway as a whole.