System.tag.configure() question with scripting

I have two sets of code. The first one works just fine. but the second one does not. There is one difference in that there are multiple parameter's in the second code. My question is why does ignition update the UDT instances on the first code, but not the second?

first code(works fine):

		"""Changes the Definintion's valuesource to OPC
			• Fill in UDTFolderPath - This will change based on tag provider
			
		"""
		system.perspective.print("Process Started")
		# import libraries
		import csv
		from datetime import datetime
		# get our dates and time to put into file name
		now = datetime.now()
		now_str = now.strftime("%Y-%m-%d_%H%M")
		
		# functions:
		def createCSVOutPut(headers, dataSet, saveLocation):
			""" create a dataSet with list, then make it a CSV file and save it to location provided
			   • Creates a CSV file based on headers and data provide to teh dataSet.
			   • headers and dataSet must be a list
			"""
			DataSet = system.dataset.toDataSet(headers, dataSet)	
			csv = system.dataset.toCSV(DataSet)
			system.file.writeFile(saveLocation, csv)
		
		# variables needed
		configsCSVDict = {} # black Dict to keep CSV/Ignition info in - helps with faster processing times
		totalCount = 0 # total tags looked at
		tagUpdateCount = 0 # tags updated
		dataSet = [] # empty list to create our CSV file
		
		
	#	*******************************************************************************************************Change as needed
		# for csv file out put
		headers = ['TagPAth', 'Update Status', 'Updated Value/Status']
		# location where CSV file will write to
		saveLocation = r"C:\Users\rkj823_ca\Desktop\Ignition Scripting File\Tag updates_" + now_str +  ".csv" 
		
		# Path that gets infrom from a SCV file for us to work on
		csvPath = r"C:\Users\rkj823_ca\Desktop\Ignition Scripting File\get tags paths paramaeters.csv"
		# main folder path in ignition's UDT Definitions to start on
		UDTFolderPath = "[Cochina]STX"
		
	#	*******************************************************************************************************Change as needed
		

		
		# Open CSV and put CSV file into the dict - Can be done with ignition tag objects as well
		with open(csvPath, 'rU') as csvFile:
			csvReader = csv.reader(csvFile, delimiter=',')
			next(csvReader)
			for row in csvReader:
				totalCount += 1
				tagPath = row[0]
				CSVparameter = row[1]
				configsCSVDict[tagPath] = CSVparameter
				
	
				
		#here to get full tag path so we can update tags accordingly -True so we get all UDT instnances
		browse = system.tag.browse(UDTFolderPath, filter= {'tagType':"UdtInstance", "recursive":True})
	
		for tagBrowse in browse:
			# path of UDT definition without tagName for system.tag.configure function updates
			IgnitionTagPath = tagBrowse['fullPath']
			# get tag configs - False so we do not get all Atomic Tags only the UDT Instance configs
			UDTInstanceConfigs = system.tag.getConfiguration(IgnitionTagPath, False)

			for UdtInstance in UDTInstanceConfigs:
				ignitionTagPath = str(UdtInstance['path'])
				udtFolderPath = ignitionTagPath.rsplit("/",1)[0]

				if ignitionTagPath in str(configsCSVDict):
					
					parameterValue = None
					# some paths have a single tag componet so it has the tag name - This try will group those for us in a CSV file to work on 
					try:
						# use ignition current path to grab the tag decription from the  CSV file
						parameterValue = configsCSVDict[ignitionTagPath]
					except KeyError as e:
						dataSet.append([ignitionTagPath, "Key Error in CSV Dict", "Single Tag Component/has a tag name instead of UDT instance"])
						break # Exit the inner loop and proceed to the next tagBrowse

					# this was added due to the try except stopp the script from writing to the UDT parameter
					if parameterValue != None:
						UdtInstance['parameters']['L3'] = parameterValue
						system.tag.configure(udtFolderPath, UdtInstance, 'm') # update tag properties
						dataSet.append([ignitionTagPath, "Updated", parameterValue]) # add to our list
						tagUpdateCount += 1

				else:
					dataSet.append([ignitionTagPath, "No Update made", "UDTPath not in CSV"])# add to our list
					

		# Call the make CSV file function	
		createCSVOutPut(headers, dataSet, saveLocation)		
				
					
		# finsihed and print out updates			
		system.perspective.print("Process Finished")
		system.perspective.print("%d out of %d tags were updated check file named: Tag updates " % (tagUpdateCount, totalCount))

Second code(Does not work):

	system.perspective.print("Process Started")
	
	import csv
	from datetime import datetime
	
	ignitionTagpath = self.getSibling("TagPath").props.text
	CSVDict = {} # for faster processing
	collisionPolicy = "m"
	csvFilePath = r"\\CSWAPPFEGPV01\c$\Users\rkj823_ca\Desktop\Update UDT parms 7-17-2023-One tag test.csv"
	
	# put ignition configs into a dict so we can process our CSV file faster
	with open(csvFilePath, 'rU') as csvfile:
	    readerObj = csv.DictReader(csvfile, delimiter=',')
	    for row in readerObj:
	        tagPathToUpdate = row["Ignition UDT Instance Path"]
	        Facility = row['Facility']
	        site = row['site']
	        service = row['service']
	        facilityid = row['facilityid']
	        parameters = { 
	            'Facility': Facility,
	            'site': site,
	            'service': service,
	            'facilityid': facilityid
	        }
	        CSVDict[tagPathToUpdate] = parameters
	
	browse = system.tag.browse(ignitionTagpath, filter={"tagType": "UdtInstance", "recursive": True})
	
	for tagBrowse in browse:
	    CurrentTagPath = tagBrowse['fullPath']
	    configs = system.tag.getConfiguration(CurrentTagPath, False)
	    for config in configs:
	        configPath = str(config['path'])
	        TopFolder = configPath.rsplit("/", 1)[0]
	
	        if configPath in CSVDict:
	            config['parameters']['Facility'] = CSVDict[configPath]['Facility']
	            # config['parameters']['Site'] = site
	            # config['parameters']['Service'] = service
	            # config['parameters']['FacilityID'] = facilityid
	
	            system.tag.configure(TopFolder, config, "m")
	
	system.perspective.print("Process Finished")

Never mind. Its Monday and I forgot I was on a read only server. I'd delete this post but could not see how.

No, it's good to keep. Sometimes the simple answers are worth reminding everyone.

4 Likes

EDIT
One way we go this to work was we put in the code to wipe the custom property clean aka take off the old overrides, put in the new value with script and then it would update correctly


Ok follow question. This code updated our custom properties perfectly. The issue is that even though the binding is showing out in ignition and binding as a parameter, the out put is still the old binding.
example. This current, one of many, binding has {Site}.{Service}:{Facility}_LT but the out put shows _AT, at the end. IF we open up the binding delete a character and put it bad it works just fine.

Is there something I am missing on why the updates are not taking effect?
Picture examples:
Currently in binding from script

Output that did not change:
MicrosoftTeams-image (3)

Have you tried restarting the tag?

I have found that sometimes when I make changes like this before they take effect in the instances, I need to restart the tag. You can do this by right clicking on the tag, the bottom option should say "Restart Tag"

Oh interesting. Is there a way to do that for all tags at once?
I ask because there are about 77k+ tags that would need that done

1 Like

Quite possibly. The only way I know of is restarting the gateway, and I'm sure that isn't always in the cards. :rofl:

You can restart a folder, but I don't know if that is recursive or not.

I don't know of any scripted way to do it.

1 Like

Oh I found some Ignition Documentation on this:

Understanding Tags

5 posts were merged into an existing topic: Ignition User Manual updates

Hey Kevin,
I don't know how i ended up here but I hope I'll get some help, I am working with pymodbus library to write a script that detect the devices that use Modbus over TCP/IP and retrieve some information about the make, model of the device (say power meter). Where exactly is this information stored? how do i find?