Is there any way to export client tag values and save it as a file, XML or something? Basically, I would like to save all the tag values, then if the client is closed, I can import that file of values back in and pick up where I left off. The reason I’m not using the database to save these values, is because some are of dataset type. The dataset types are dynamic and unpredictable as what will be in them. I don’t want to use any gateway tags to save my values because I would have to have a set of gateway tags for every client that might use the project, plus I might want to save multiple sets of tag values. There maybe another way around this, any suggestions?
It’s easy to save datasets as CSV and load CSV into datasets. We use this to backup/restore dataset tags, as well as keep versions (save a copy of CSV with date and time each time dataset tag changes).You could also save tag names and values to CSV and then parse the CSV to get a list of tags and values to write on load. Getting datasets and single value tags into the same file is possible, but more complex. If it’s not too crazy, I’d probably save dataset(s) as individual CSV file(s) and then another CSV file for tags with single values (first column tag names, second column values).
I have the datasets saving as separate CSVs currently, but nothing for single valued tags. How would I go about saving/uploading all single value tags as a single csv?
EDIT: Thinking about it a minute, I guess I could use system.tag.readAll()
and save it the same way as the dataset tags.
Yes, on more thought I’d put the tags in columns with a single row of values (so column types can match tag value types). Here’s some code to play with in script console. I left out the saving/opening dataset part as you’re already doing that.
# Get tags and values to backup.
tags = ['someTagPath', 'someOtherTagPath', 'yetAnotherTagPath']
#values = [[x.value for x in system.tag.readAll(tags)]]
# Below line for testing in script console. Uncomment line above and delete line below.
values = [[1, 2.0, 'String 1']]
# Put values into dataset with tag paths as column names and tag values in first row.
data = system.dataset.toDataSet(tags, values)
print data
# Retrieve tag names and values from dataset for restore via system.tag.writeAll.
tags = [data.getColumnName(i) for i in range(data.getColumnCount())]
values = [data.getValueAt(0, i) for i in range(data.getColumnCount())]
print tags
print values
# Print a more human friendly list for testing.
for i, tag in enumerate(tags):
print data.getColumnName(i), data.getValueAt(0, tag)