[Feature-2684]Scripting - Tag group - Create / Delete

Is something wrong with the code?
i dont think there is something enw related to tags yet, but i dont really follow those changes a lot.

Nothing wrong with the code, it works just fine. My only issue is the need to use a message vs using a native method. @PGriffith is this a feature request and is there any activity on it?

It hasn’t been picked up, but even if it did you’d have to send a message because it would only be implemented in the gateway scope.

1 Like

For future reference, it is possible to edit Tag Group configurations using a script as hinted by @victordcq

This is how I implemented it in a tag value change script:

This script would save a new tag group which is a copy of the Tag Group at index [4] with a different name and a different mode.

If I had only changed the mode it would have edited the tag group and changed the mode. Using provider.saveTagGroupsAsync will edit the tag group if that name already exists. To avoid a NullPointer exception I had to retrieve each property from the reference tag group instead of creating a new one from scratch. I left the lines as a comment for the curious.

	if currentValue.value == True:

		import copy
		from com.inductiveautomation.ignition.gateway import IgnitionGateway
		from com.inductiveautomation.ignition.common.tags import config
		from com.inductiveautomation.ignition.common.config import PropertySet,  Property, BasicProperty, PropertyValue , BasicPropertySet, BasicDescriptiveProperty
		
		provider = IgnitionGateway.get().getTagManager().getTagProvider('default')
		taggroups = provider.getTagGroupsAsync().get()
		

		
		tagGroupConfig = taggroups[4].getConfig()
		
		try:
		
		
			newTagGroupConfig = BasicPropertySet()
			

					###This loop copies properties
			for prop in tagGroupConfig:
				if str(prop.getProperty().name) == str(u'mode'):
					
					propValue = PropertyValue(prop.getProperty(),'Leased')	
					
					propSet = newTagGroupConfig.set(propValue )	

				elif str(prop.getProperty().name) == str(u'name'):
						
#					newProp = BasicDescriptiveProperty()	
#					newProp.setName('name')
					propValue = PropertyValue(prop.getProperty(),'TagGroupName')	
					
					propSet = newTagGroupConfig.set(propValue )	

				else:

					propValue = prop
					
					propSet = newTagGroupConfig.set(propValue )	
			
			newConfig = config.TagGroupConfiguration(newTagGroupConfig)
			
#			taggroups.append(newConfig)
			
			

			result = provider.saveTagGroupsAsync([newConfig]).get()

		
		
			system.tag.writeBlocking(tagPaths=[tagPath], values=[False])

		except Exception as e:
		
			system.tag.writeBlocking(tagPaths=["[.]tagGroupConfig"], values=[e.args])
		
			system.tag.writeBlocking(tagPaths=[tagPath], values=[False])


3 Likes