[IGN-2684]Import / Export tag group settings

Is there a way to import / export tag group settings via scripting?
I want to add these settings to an automated tag import/export when using a git workflow - they are easily forgotten when setting up a project.

In the designer there is a possibility to import and export these settings to a JSON file, however I can not find any commands in the scripting library. (e.g. Like system.tag.exportTags).

Are they somehow accessible through the SDK? E.g.with TagProvider.getTagGroupsAsync()?
Or is there an easier way to directly trigger a JSON export / import?

It’s probably doable through the SDK, but there’s no readily accessible, supported method to do so (yet) that you’re missing. I’ve added this thread to our internal ticket requesting the feature.

I managed to build a simple export / import function using the SDK.
We can get the individual tag group configs and serialize them into a file. For the import they can be deserialized and loaded back to the tag providers.

However I am aware that this is not supported and might cause problems with future versions.

Thank you, having an officially supported way to achieve this would be really helpful.

Here is the export code as an example:
(if anyone wants to build something similar, do not forget to add proper error handling)

from com.inductiveautomation.ignition.gateway import IgnitionGateway
from com.inductiveautomation.ignition.common.tags.config import TagGroupConfiguration
from java.io import ObjectOutputStream, FileOutputStream
	
EXPORT_PATH = "C://yourpath/"
EXPORT_FILENAME = "TagGroupExport.txt"
logger = system.util.getLogger("myLogger")
context = IgnitionGateway.get()

tagManager = context.getTagManager()
providerNames = tagManager.getTagProviderNames()
logger.info("Provider Names " + str(providerNames))
	
for name in providerNames:
	provider = tagManager.getTagProvider(name)
	tagGroupsConfig = provider.getTagGroupsAsync().get()
	logger.info("Exported TagGroups: " + str(tagGroupsConfig))
	
	f=FileOutputStream(EXPORT_PATH + name + EXPORT_FILENAME)
	o = ObjectOutputStream(f)
	o.writeObject(tagGroupsConfig)
	logger.info("Tag Groups " + name + " Exported")
4 Likes

@PGriffith : is tag group import/export via system.tag.* library something that might materialize in soon-ish ignition releases? Thanks!

+1 for this feature for 8.1, import will be very useful !

@PGriffith, perhaps a feature for:

1 Like

Any traction on this feature? Would love to use it in conjunction with system.tag.exportTags for git :frowning:

The OP already provided a way to do it using the sdk, any reason you can't use that?

Haven't used sdk to build our own modules, let me look into it.

No need to build a module, just need to copy and paste the code into a gateway scoped script area. By 'sdk' we're really talking about the javadocs

Hello,

Based on @reto.kunz code i made a code that do exactly the same than Group Tags Export.

logger = system.util.getLogger("GatewayEvent.Scripts.Update")

from com.inductiveautomation.ignition.gateway import IgnitionGateway
from com.inductiveautomation.ignition.common.tags.config import TagGroupConfiguration
import json

context = IgnitionGateway.get()
tagManager = context.getTagManager()

#I am working in project named edge
provider = tagManager.getTagProvider("edge")

tagGroupsConfig = edgeProvider.getTagGroupsAsync().get()

tagGroupsConfigExport = []

for tagGroupConfig in tagGroupsConfig:
	
	configs = tagGroupConfig.getConfig()
	
	tagGroupConfigExport = {}
	
	for config in configs:
		if isinstance(config.getValue(), (int, bool, float)):
			tagGroupConfigExport[str(config.getProperty())] = config.getValue()
		else:
			tagGroupConfigExport[str(config.getProperty())] = str(config.getValue())
	
	tagGroupsConfigExport.append(tagGroupConfigExport)
	
jsonTagGroupsConfig = json.dumps(tagGroupsConfigExport, indent=4, sort_keys=True)
#jsonTagGroupsConfig = system.util.jsonEncode({"list": tagGroupsConfigExport}, 4)

system.file.writeFile("data\\projects\\tagGroups.json", jsonTagGroupsConfig) 

My code is executed when my project is saved (Gateway Event Update) in order to save in git every modification.