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

Unfortunately there doesn’t seem to be anything for manipulating tag groups there. Those set of functions only seem to encompass tag manipulation (as far as I can see).

That makes sense and it could be quite useful. If you don’t get an answer definitely look into making a feature request.

I was about to say to put it in the ideas portal. :slight_smile:

I thought there was already one there, but I don’t see it.

1 Like

You’re not missing anything, but yes, this should definitely be possible.

2 Likes

On a related note, do any of you know if there currently is a way to retrieve a list of existing tag groups via scripting?

How is going this feature?

I just came to a situation when this would be a very useful feature...

this will get you a list of all the tags of the given provider (this case default)

from com.inductiveautomation.ignition.gateway import IgnitionGateway
provider = IgnitionGateway.get().getTagManager().getTagProvider('default')
taggroups = provider.getTagGroupsAsync().get()
names = [x.getName() for x in taggroups]

there is also saveTagGroupsAsync() and removeTagGroupsAsync()
https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.0/com/inductiveautomation/ignition/common/tags/model/TagProvider.html#getTagGroupsAsync()

3 Likes

Thank you, but this is what I get (v8.1.10):

you can not use this in the script console

1 Like

OK, thank you, but I need this in Vision, not Perspective…

Send a message to a message handler.

Ok, but from where?
Sorry but … I’m :confused:

Wherever you needed it in Vision?

Define a gateway message handler in your project that will run @victordcq’s gateway-scoped code. Call that message handler from anywhere in Vision Client scope using system.util.sendMessage or sendRequest.

2 Likes

Now I understand.
Thank you. :+1:

1 Like

Is this the only way (or at least the best/easiest way) to get a list of tag groups?

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])


2 Likes