Write to object Parameter via script

8.1.41 - perspective.

I have a view with custom parameter object - custom.Data

What I am trying to do is one a button is pressed to copy a specified tag values into custom.Data (this is a one time thing direct or indirect tag bindings will not work)

this is my button event script

	#get path of tag UDT to read from
	tagPath = self.getSibling("Dropdown").props.value
	#get data parameter
	data = self.view.custom.Data

	tagPaths = []	
	
	#go through keys in data and get matching tag values from UDT
	for key in data.keys():
		if key[:10] == "Parameters":
			keyN = key.replace('_','.')
		else:
			keyN = key.replace('_','/')
		tagPaths.append(tagPath+'/'+keyN)
	values = [qval.value for qval in system.tag.readBlocking(tagPaths)]
	
	#write tag values back into data
	for key,value in zip(data.keys(),values):
		data[key]=value
	
	#clear these values
	data['Config_PLC_Point']=''
	data['Parameters_TagName']=''
	
	#write back to parameter
	self.view.custom.Data = data

Based on what I am seeing if I run this same script in script console it is working except writing back to the custom.Data parameter results in all values being blank

Script console

tagPath = '[IO1]PLC1/Inputs/7'
data = {
  "Config_InputType": "",
  "Config_PLC_Slot": "",
  "Parameters_Room": "",
  "Config_AI_AlarmHiHiSP": "",
  "Config_AI_MinimumEGU": "",
  "Parameters_GasType": "",
  "Parameters_EGU": "",
  "Parameters_FullScale": "",
  "Config_AI_AlarmLoLoSP": "",
  "Parameters_Location": "",
  "Parameters_Matrix": "",
  "Parameters_AlarmDescription": "",
  "Config_DI_NoGasActions": "",
  "Parameters_Decimals": "",
  "Parameters_Port": "",
  "Parameters_Description": "",
  "Parameters_PLC": "",
  "Config_AI_AlarmHiSP": "",
  "Config_PLC_Point": "",
  "Config_PLC_Rack": "",
  "Config_AlarmDelay": "",
  "Config_DI_NormalState": "",
  "Parameters_TagName": "",
  "Config_AI_MaximumEGU": "",
  "Config_AI_AlarmLoSP": "",
  "Parameters_DisplayPath": ""
}

#tagPath = self.getSibling("Dropdown").props.value
#data = self.view.custom.Data
print data
tagPaths = []	

#go through keys in data and get matching tag values from UDT
for key in data.keys():
	if key[:10] == "Parameters":
		keyN = key.replace('_','.')
	else:
		keyN = key.replace('_','/')
	tagPaths.append(tagPath+'/'+keyN)
values = [qval.value for qval in system.tag.readBlocking(tagPaths)]

#write tag values back into data
for key,value in zip(data.keys(),values):
	data[key]=value

#clear these values
data['Config_PLC_Point']=''
data['Parameters_TagName']=''

#write back to parameter
#self.view.custom.Data = data
print data

console results

>>> 
{'Config_InputType': '', 'Config_PLC_Slot': '', 'Parameters_Room': '', 'Config_AI_AlarmHiHiSP': '', 'Config_AI_MinimumEGU': '', 'Parameters_GasType': '', 'Parameters_EGU': '', 'Parameters_FullScale': '', 'Config_AI_AlarmLoLoSP': '', 'Parameters_Location': '', 'Parameters_Matrix': '', 'Parameters_AlarmDescription': '', 'Config_DI_NoGasActions': '', 'Parameters_Decimals': '', 'Parameters_Port': '', 'Parameters_Description': '', 'Parameters_PLC': '', 'Config_AI_AlarmHiSP': '', 'Config_PLC_Point': '', 'Config_PLC_Rack': '', 'Config_AlarmDelay': '', 'Config_DI_NormalState': '', 'Parameters_TagName': '', 'Config_AI_MaximumEGU': '', 'Config_AI_AlarmLoSP': '', 'Parameters_DisplayPath': ''}
{'Config_InputType': 101, 'Config_PLC_Slot': 1, 'Parameters_Room': u'1', 'Config_AI_AlarmHiHiSP': 0.0, 'Config_AI_MinimumEGU': 0.0, 'Parameters_GasType': 1L, 'Parameters_EGU': u'', 'Parameters_FullScale': 0.0, 'Config_AI_AlarmLoLoSP': 0.0, 'Parameters_Location': u'Outside North Door', 'Parameters_Matrix': 4L, 'Parameters_AlarmDescription': u'EGO activated Bld 10 Room 303 North door', 'Config_DI_NoGasActions': False, 'Parameters_Decimals': None, 'Parameters_Port': u'3', 'Parameters_Description': u'EGO button', 'Parameters_PLC': u'1', 'Config_AI_AlarmHiSP': 0.0, 'Config_PLC_Point': '', 'Config_PLC_Rack': 2, 'Config_AlarmDelay': 30, 'Config_DI_NormalState': False, 'Parameters_TagName': '', 'Config_AI_MaximumEGU': 0.0, 'Config_AI_AlarmLoSP': 0.0, 'Parameters_DisplayPath': 1L}
>>> 

any Ideas on how I can get the values into the custom.data?

What is the datatype of custom.Data value object or array?

Object

You are likely running into a known issue with the python wrapper on ignition perspective property objects. It causes issues when trying to modify the value of keys in dictionary like objects.

Run the data object through this piece of code:

def sanitizeIgnitionObject(element):
	""" """
	if hasattr(element, '__iter__'):
		if hasattr(element, 'keys'):
			return dict((k, sanitizeIgnitionObject(element[k])) for k in element.keys())
		else:
			return list(sanitizeIgnitionObject(x) for x in element)
	return element

Ie. data = sanitizeIgnitionObject(self.view.custom.Data)

That will turn the objects into actual python objects that will allow you to modify the key's values.

1 Like

Thank you, worked perfectly